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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]