This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts 2 validation: how to prevent validation messages from appearing by default Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 validation: how to prevent validation messages from appearing by default" Watch "Struts 2 validation: how to prevent validation messages from appearing by default" New topic
Author

Struts 2 validation: how to prevent validation messages from appearing by default

Tom George
Ranch Hand

Joined: Jan 28, 2004
Posts: 41

The problem described must be commonplace and surely must have been discussed before. Apologies for bringing it up again.

I have a simple action class named say Hello in struts.xml, and have the validations specified in xml (Hello-validation.xml). The messages come up when invoking Hello. How do we prevent the messages from appearing when invoking 'hello.action'? They should appear only when the user posts the form.

Read somewhere that S2 will ensure this when the action class returns INPUT. That does not seem to work. A bit curious about the best practice to follow here...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Posting to the form shouldn't be handled by the same means used to reach the form initially. Either display the form via the action's input() method (validation is bypassed for a small list of action methods), or display the form initially through a different action definition.

(Or differentiate between GET and POST in an interceptor, and automagically call input() when it's a GET request.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 validation: how to prevent validation messages from appearing by default