• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Advice for Struts forms with validation

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i understand correct in your question :

You can save data in request/session scope
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can save data in request/session in validate() method of ActionForm file

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic