struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Thomas <guy.tho...@vlaamsbrabant.be>
Subject RE: Repopulating rich controls
Date Mon, 19 Jul 2010 13:59:20 GMT
Hello Greg,

What I did, is explained and illustrated with code in my first mail (see below).

To recap:

1. I used an action tag, not the prepare interface.

   So in index.jsp I used in the form:

   <s:action name="bookactions" namespace="/" executeResult="true" />

   The "bookactions" action refers to the following jsp.

   <%@ taglib prefix="s" uri="/struts-tags"%>
   <s:radio list="bookActions" value="defaultBookAction" name="bookAction"
    onclick="setTextFieldVisibility (this.value)" theme="simple" />

2. The form target action is "bookactiondispatcher".

3. This is the validate method in the bookactiondispatcher Action class:

   @Override
   public void validate ()
   {
      logger.debug ("Validating an action dispatch ...");

      if (bookAction.equals (SEARCH) && (searchString == null || searchString.equals
("")))
         addActionError (getText ("bookindexer.error.search.nosearchstring"));
   }

So I did everything as explained on the referred web page, but it didn't work. Only then did
I dare submit my question on the forum.

Best regards,

Guy Thomas
   

-----Oorspronkelijk bericht-----
Van: Greg Lindholm [mailto:greg.lindholm@gmail.com] 
Verzonden: maandag 19 juli 2010 15:39
Aan: Struts Users Mailing List
Onderwerp: Re: Repopulating rich controls

What you are describing as "odd" behavior is actually normal and expected. With Struts the
URL shown in the browser will always be the "action" name it will never be the jsp. You may
wish to read up a little on how Servlets and forwarding works (just google "servlet forward").

Just replying "I did what you said and it didn't work" (this list get messages like this every
day) doesn't provide any additional information that would allow someone to help you.

Did you implement the Preparable interface?  Did you run your app in the debugger and break
in your prepare() method?  What does you prepare method look like?

The best way to get help is to provide a detailed description of what you actually did including
code and configuration samples.

The best way to help yourself (and learn) is to run your app in the debugger and find out
what it is actually doing.

On Mon, Jul 19, 2010 at 1:51 AM, Guy Thomas <guy.thomas@vlaamsbrabant.be> wrote:
> Hello Greg,
>
> I had tried to apply the instructions on the web page you sent me, but as explained in
my mail, it did not work. I must have done something wrong.
>
> One of the symptoms of an "odd" behavior is that I'm taken back to the jsp page with
the form (index.jsp) when I forget to fill in something in the search text field, but that
the url still shows the target action of the form and ... the rich controls are not repopulated.
>
> Guy
>
> -----Oorspronkelijk bericht-----
> Van: Greg Lindholm [mailto:greg.lindholm@gmail.com]
> Verzonden: vrijdag 16 juli 2010 19:38
> Aan: Struts Users Mailing List
> Onderwerp: Re: Repopulating rich controls
>
> From the Struts 2 FAQ
>
> http://struts.apache.org/2.1.8.1/docs/how-do-we-repopulate-controls-wh
> en-validation-fails.html
>
>
> On Fri, Jul 16, 2010 at 4:40 AM, Guy Thomas <guy.thomas@vlaamsbrabant.be> wrote:
>> In a form I use the struts2 action tag to populate a drop down list:
>>
>> <s:actionerror />
>>
>> <s:form action="bookactiondispatcher" namespace="/" theme="simple">
>>      <table>
>>            <tr>
>>                  <td>Select an action:</td>
>>                  <td><s:action name="bookactions" namespace="/"
>> executeResult="true" /></td>
>>            </tr>
>>
>>            <tr>
>>                  <td>Specify search terms:</td>
>>                  <td><s:textfield name="searchString" size="44"
>> required="true" /></td>
>>            </tr>
>>
>>            <tr>
>>                  <td><s:submit type="input" value="Voer actie uit"
>> /></td>
>>            </tr>
>>      </table>
>> </s:form>
>>
>>
>> The "bookactions" action refers to the following jsp (bookactions.jsp):
>>
>> <%@ taglib prefix="s" uri="/struts-tags"%> <s:radio list="bookActions"
>> value="defaultBookAction" name="bookAction"
>> onclick="setTextFieldVisibility (this.value)" theme="simple" />
>>
>> As long as I select the select action (there is also an index action) and enter search
terms, there is no problem; the user is taken to the search result page.
>>
>> However, the code for the bookactiondispatcher action contains a validate method:
>>
>>   @Override
>>   public void validate ()
>>   {
>>      logger.debug ("Validating an action dispatch ...");
>>
>>      if (bookAction.equals (SEARCH) && (searchString == null || 
>> searchString.equals ("")))
>>         addActionError (getText
>> ("bookindexer.error.search.nosearchstring"));
>>   }
>>
>> When the user selects the search action and forgets to specify search terms, he/she
is taken back to the page with the form:
>>
>> <action name="bookactiondispatcher"
>> class="be.vlaamsbrabant.bookindexer.actions.BookActionDispatcher">
>>         ...
>>         <result name="input">/index.jsp</result>
>>         ...
>>
>> However:
>> - On the "input result" page the rich control for the possible book actions is no
longer filled up.
>> - I "see" the contents of index.jsp (with the form), but the URL is 
>> http://.../bookindexer/bookactiondispatcher.action (the url for the 
>> form action.)
>>
>> I had exactly the same problem in another application. There I removed the validate
method and used a specific error result to redirect the user to an error page.
>>
>> How I can still use struts2  validation and have my rich controls (re-)populated
when being redirected through an input result?
>>
>>
>>
>> -------------
>> Aan dit bericht kunnen geen rechten worden ontleend. Alle berichten naar dit professioneel
e-mailadres kunnen door de werkgever gelezen worden.
>> Ondernemingsnummer: 0253.973.219
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> -------------
> Aan dit bericht kunnen geen rechten worden ontleend. Alle berichten naar dit professioneel
e-mailadres kunnen door de werkgever gelezen worden.
> Ondernemingsnummer: 0253.973.219
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




-------------
Aan dit bericht kunnen geen rechten worden ontleend. Alle berichten naar dit professioneel
e-mailadres kunnen door de werkgever gelezen worden.
Ondernemingsnummer: 0253.973.219


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message