aspose file tools*
The moose likes Struts and the fly likes Advice for Struts forms with validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Advice for Struts forms with validation" Watch "Advice for Struts forms with validation" New topic
Author

Advice for Struts forms with validation

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Hi all,

I have the current situation:
I have a struts form, which captures some data from HTML forms. I added some restrictions on it, like xxx field must contain only 6 characters, etc, and I define the validation rules from validate.xml.

For example, the value of the field is originally XXXXYYYY, when I click submit, since it violates the rules defined in validate.xml, an error message is shown, but then, the value of the field disappeared!!!

Any tricks I can use to preserve the field, even though it contains an invalid value? I have already set the forms as session.

I understand that the error handling of Struts engine, it will NOT call the action method defined ActionDispatch nor the validate method inside the form, thus, I have no *programming* ways to save the updated value from the request.

Any ideas are appreicate.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
If i understand correct in your question :

You can save data in request/session scope


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
But where can I access to the request/session, if the form data cannot be validated by validator.xml?

If I turn this feature on, if the checking cannot be passed, all the rest *rountines* will be bypass, and the control will be redirect to the JSP with error message (Thus, validate() in Form, and action in ActionDispatcher will NOT be called).

Nick
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
But where can I access to the request/session, if the form data cannot be validated by validator.xml?


You can keep input data if validate data in server-side.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
You can save data in request/session in validate() method of ActionForm file

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advice for Struts forms with validation