• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Advice for Struts forms with validation

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

 
reply
    Bookmark Topic Watch Topic
  • New Topic