File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes By pass Struts Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "By pass Struts Validation" Watch "By pass Struts Validation" New topic

By pass Struts Validation

Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 128
I am doing struts validation server side. How do I by pass validation during runtime, because I have 2 buttons on the same form. One is accept and another is save. When I click save it should by pass validation during run time.

Thank you,
Paul Lester
Ranch Hand

Joined: Dec 27, 2002
Posts: 40
There is nothing in struts that requires that you do validation. When you click the submit button, the framework will call the ActionForm.validate method. You need not override that method at all and no validations will be done. The method will still be called on the parent class, ActionForm, but it will never return any errors.

Where Photography meets vision.<br /><a href="" target="_blank" rel="nofollow"></a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
Luke Zechariah
Ranch Hand

Joined: Sep 27, 2005
Posts: 128
Hello All,

Just now found the answer of how to by pass validation in struts. To allow the user to cancel the submit and bypass the validations, a flag can be set. If the Submit button sets bCancel to true, then the Struts Validator will pass control through to the Action.


PS: The "click" was mis-spelled debilrately. But in real coding do spell it in the proper way.
Aaron Ting
Ranch Hand

Joined: Dec 13, 2005
Posts: 78
Actually, regarding this requirement you are talking about, if i am not wrong, the developer can actually set whether the method needs to be validated via the struts-config.xml..

For example, i have this method, "/add".. so the coding goes,

Hope this information helps..

[ December 19, 2005: Message edited by: Aaron Ting ]

If you can't convince them, confuse them!
I agree. Here's the link:
subject: By pass Struts Validation
It's not a secret anymore!