>   <action path=      "/ProcessCountryForm"
>           type=     
> "com.example.action.ProcessCountryFormAction"
>           scope=     "request"
>           name=      "countryForm"
>           input=     "/SetUpCountryForm">
>       <forward name= "success"
> path="success-page" redirect="false"/>
>       <forward name= "failure"
> path="error-page" redirect="false"/>
>   </action>
> 
Note that the input attribute value must be the URI and
not just the action mapping name. So in your /ProcessCountryForm
configuration, input should be /do/SetUpCountryForm or /SetUpCountryForm.do
which ever you use.


> In addition to this, the actual JSP has to
> be non-static, that is, it is JSPs
> responsibility to take any data it needs
> from the HTTP Request and populate the HTML
> form with it, is that correct? (i.e. this is
> not done auto-magically by Struts - it is up
> to the JSP developer to add code to do that
> to the JSP)?
No. Struts will automatically populate the form if
you are using the appropriate <html:*/> tags.


robert

> -----Original Message-----
> From: otisg [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 19, 2003 2:44 PM
> To: Robert Taylor; Struts Users Mailing List
> Subject: RE: RE: handling form errors in Actions, returning to form,
> prepopulating them without re-POSTING
> 
> 
> Aha!  Thank you for clarifying this.
> So, in Struts config-speak, is this all that
> is needed to do what you described:
> 
> <action-mappings>
> 
>   <action path=      "/SetUpCountryForm"
>         type=     
> "com.example.action.SetUpCountryFormAction"
>           scope=     "request"
>           name=      "countryForm"
>           input=    
> "/WEB-INF/country-form.jsp">
>       <forward name= "success"
> path="country-form-page" redirect="false"/>
>       <forward name= "failure"
> path="error-page" redirect="false"/>
>   </action>
> 
>   <action path=      "/ProcessCountryForm"
>           type=     
> "com.example.action.ProcessCountryFormAction"
>           scope=     "request"
>           name=      "countryForm"
>           input=     "/SetUpCountryForm">
>       <forward name= "success"
> path="success-page" redirect="false"/>
>       <forward name= "failure"
> path="error-page" redirect="false"/>
>   </action>
> 
> </action-mappings>
> 
> 
> In addition to this, the actual JSP has to
> be non-static, that is, it is JSPs
> responsibility to take any data it needs
> from the HTTP Request and populate the HTML
> form with it, is that correct? (i.e. this is
> not done auto-magically by Struts - it is up
> to the JSP developer to add code to do that
> to the JSP)?
> 
> Thank you,
> Otis
> 
> 
> 
> ---- On Wed, 19 Feb 2003, Robert Taylor
> ([EMAIL PROTECTED]) wrote:
> 
> > Wrong. If you look more closely I offered
> a solution that allows
> > you to avoid putting data in session scope.
> > 
> > 
> > "Rick, I usually define the setUpForm
> action URI as the input attribute
> > of the processForm action element. That
> way if a validation error occurs
> > the request is forwarded to the setUpForm
> action which repopulates the list
> > and forwards to the page where my list is
> displayed along with the error
> > message and the users input.
> > 
> > Works for me and I don't have to place
> anything in the session."
> > 
> > 
> > - SetUpAction prepares the page to be
> displayed. For example,
> >   populate the form associated with this
> action with a list of
> >   countries. Let's put the form in request
> scope.
> > 
> > - ProcessAction processes the user input. The
> >   input attribute value of the action
> element for the 
> >   ProcessAction action mapping is defined
> to be
> >   the uri which invokes the SetUpAction.
> > 
> > - When a validation error, the appropriate
> error messages are
> >   created and the request is forwarded to
> the SetUpAction where
> >   the page is prepared. The request
> contains all the user input
> >   and the SetUpAction (once again)
> populates the countries in 
> >   the form.
> > 
> > - The request is then forwarded to the
> .jsp page where the 
> >   data which the user entered is rendered
> along with their
> >   invalid input which caused the
> validation errors.
> > 
> > - Nothing in session scope.
> > 
> > To answer your specific questions:
> > 
> > > But how does one do these things:
> > > 
> > > A. Get the user back the input form
> > Upon validation error, struts will forward the
> > request to the URI defined in the input
> attribute value
> > of the action element of the action mapping
> > defined for the action which processes the
> user input.
> > In the above example would be for
> ProcessAction. 
> > 
> > > 
> > > B. Display the error message
> > Struts validation will create ActionErrors and
> > place them in the request. Assuming you
> are using
> > StrutsValidator.
> > 
> > 
> > > C. Make sure that all possible fields are
> > Since the request is forwarded, all user input
> > still exists in the request and thus the form.
> > 
> > 
> > > D. The pull-down in the form has that same
> > >    list of countries
> > Since you are being forwarded to the
> SetUpAction (see above example)
> > your countries will be re-populated.
> > 
> > robert
> > 
> > > -----Original Message-----
> > > From: otisg [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, February 19, 2003 1:37 PM
> > > To: Struts Users Mailing List
> > > Subject: Re: RE: handling form errors in
> Actions, returning to form,
> > > prepopulating them without re-POSTING
> > > 
> > > 
> > > Thanks.
> > > However, that thread really says one thing -
> > > put everything in session scope and don't
> > > worry about it :)
> > > 
> > > But how does one do these things:
> > > 
> > > A. Get the user back the input form
> > > 
> > > -- Is it by just finding a 'failure' forward
> > > that points to the original JSP with the
> form?
> > > 
> > > B. Display the error message
> > > 
> > > -- I guess the errors are saved either in
> > > Session or Request, ok.
> > > 
> > > C. Make sure that all possible fields are
> > >    pre-populated with data that the user
> > > already entered
> > > 
> > > -- Is this up to the JSP develop to do,
> > > perhaps with the help of
> > >    some Struts JSP tags or does this happen
> > > automagically?
> > > 
> > > D. The pull-down in the form has that same
> > >    list of countries
> > > 
> > > -- Yes, a developer could just save this in
> > > Session scope, but if that is not desired,
> > > then how is this re-retrieved if the user it
> > > forwarded to a JSP?  The user would need to
> > > be re-sent to the original action that
> > > retrieved the list, no?
> > > 
> > > E. The user is not prompted with 'Do you
> > >    want to re-POST' dialog
> > > 
> > > -- Does this happen automagically?
> > > 
> > > Thanks,
> > > Otis
> > > 
> > > 
> > > 
> > > 
> > > ---- On Wed, 19 Feb 2003, Robert Taylor
> > > ([EMAIL PROTECTED]) wrote:
> > > 
> > > >
> > >
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg58515.html
> > > > 
> > > > > -----Original Message-----
> > > > > From: otisg [mailto:[EMAIL PROTECTED]]
> > > > > Sent: Wednesday, February 19, 2003
> 12:39 PM
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: handling form errors in
> > > Actions, returning to form,
> > > > > prepopulating them without re-POSTING
> > > > > 
> > > > > 
> > > > > Hello,
> > > > > 
> > > > > We are starting to use Struts and are
> > > > > wondering how Struts users handle
> scenarios
> > > > > such as this one:
> > > > > 
> > > > > 1. /ShowForm action gets called,
> mapped to
> > > > > ShowFormAction.
> > > > >    ShowFormAction pulls a list of
> countries
> > > > > from the DB (for ex.),
> > > > >    stick that list in the HTTP
> request, and
> > > > > 'forwards' to 'ok', 
> > > > >    which is a JSP with a form that
> consists
> > > > > of blank form fields
> > > > >    and a pull-down with countries
> that it
> > > > > gets from the HTTP req.
> > > > > 
> > > > > 2. A user fills the form, but forgets a
> > > > > required field before he
> > > > >    submits the form by POSTing to
> > > > > /SubmitForm action.
> > > > > 
> > > > > 3. /SubmitForm is mapped to
> SubmitFormAction
> > > > > which detects a
> > > > >    missing required field.  Is puts
> error
> > > > > messages in an instance 
> > > > >    of ActionErrors.  It now needs to
> forward
> > > > > to something other
> > > > >    than 'ok'.
> > > > > 
> > > > > What we want to happen at this point is:
> > > > > 
> > > > > A. Get the user back the input form
> > > > > B. Display the error message
> > > > > C. Make sure that all possible
> fields are
> > > > > pre-populated with
> > > > >    data that the user already entered
> > > > > D. The pull-down in the form has
> that same
> > > > > list of countries
> > > > > E. The user is not prompted with 'Do you
> > > > > want to re-POST' dialog
> > > > > 
> > > > > How can this be done?
> > > > > 
> > > > > In our Struts config we have:
> > > > > 
> > > > >     <!-- gets a list of countries
> from DB,
> > > > > puts them in Request,
> > > > >          forwards to 'ok'  -->
> > > > >     <action path=      "/ShowForm"
> > > > >             type=     
> > > > > "net.wgen.ampng.action.ShowFormAction"
> > > > >             scope=     "request">
> > > > >         <forward name= "ok"      
> > > > > path="/WEB-INF/v/form-ok.jsp"/>
> > > > >         <forward name= "failure" 
> > > > > path="/WEB-INF/v/form-not.jsp"/>
> > > > >     </action>
> > > > > 
> > > > >     <!-- gets form data and
> processes it -->
> > > > >     <action path=      "/SubmitForm"
> > > > >             type=     
> > > > > "net.wgen.ampng.action.SubmitFormAction"
> > > > >             scope=     "request"
> > > > >             validate=  "true"
> > > > >             name=      "myForm"
> > > > >             input=    
> > > "/WEB-INF/v/form.jsp">
> > > > >         <forward name= "ok"      
> > > > > path="/WEB-INF/v/ok.jsp"/>
> > > > >         <forward name= "failure" 
> > > > > path="/WEB-INF/v/form.jsp"/>
> > > > >     </action>
> > > > > 
> > > > > 
> > > > > What is the best way to handle this and
> > > > > achieve A, B, C, D, and E that I
> mentioned
> > > > > above?
> > > > > 
> > > > > If SubmitFormAction encounters an error
> > > > > (e.g. a missing required field),
> what should
> > > > > it forward to?  The original JSP in
> 'input'
> > > > > attribute?  The JSP mapped to
> 'failure' (the
> > > > > same JSP with the original form)?
> > > > > Should it forward/chain to another
> Action
> > > > > that redirects back to the original
> form?
> > > > > (but that would lose the form data +
> error
> > > > > messages in the Request, wouldn't it?) 
> > > > > Something else?
> > > > > Does the JSP with the form need to
> contain
> > > > > the logic for pulling errors + form data
> > > > > from the request, if it exists?
> > > > > 
> > > > > This seems like a situation that
> would be
> > > > > very common and I feel that Struts
> has some
> > > > > elegant way for handling this.
> > > > > 
> > > > > Thank you,
> > > > > Otis
> > > 
> > > 
> > >
> ________________________________________________
> > > Get your own "800" number
> > > Voicemail, fax, email, and a lot more
> > > http://www.ureach.com/reg/tag
> > > 
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> [EMAIL PROTECTED]
> > > 
> > 
> > 
> 
> 
> ________________________________________________
> Get your own "800" number
> Voicemail, fax, email, and a lot more
> http://www.ureach.com/reg/tag
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to