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

how to disable struts validation

jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
is there a way to disable struts validation by setting a flag in the form that i submit? By default i want the validation for certain form to be on, but occasionally i want to skip it.
thanks in advance
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
Are you using the validator framework?

Or are you making your own forms with their own validation?

If you are making your own forms, it should be easy enough to add a parameter that says if you should validate or not.

Best of Luck,

Nate
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
I am using struts validator framework. any idea?

And also it seems like struts validator does not check the required field correctly if the field type is radio.. If i have a list of radios and none is selected. and the radio name is required, struts does not catch the missing selection.. what's wrong??
thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm not sure how to turn off validation if you're using the validation framework, but regarding your radio button problem, I suspect that if you add a reset() method to your ActionForm and set the value of the property controlled by the set of radio buttons to "", the validation will work properly. The trouble with radio buttons is that they don't send anything to the server if they're unchecked. The reset() method gets around this problem by always setting a default value for the form's properties. Check the user guide for the correct signature of the reset() method.


Merrill
Consultant, Sima Solutions
anupa oru
Ranch Hand

Joined: Jan 15, 2005
Posts: 118
Hi,
as of my knowledge I think you have to remove plug in for validator framework in struts-config.xml.It may be silly reason for expert like you, you may already done that.I am learning struts pls excuse me if I am wrong and correct me if you can.
Thanks in advance
Anupa
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

It is a very common thing to have certain buttons on your page not call validation.

Here are some of the options that I know of:
1) Extend RequestProcessor and implement your own way (not my preference)
2) In the validate() method of your ActionForms, only call super.validate() when the button that needs validations was the one clicked. [super.validate() is what calls the validator framework]
3) I think that the RequestProcessor already ignores validation on cancel buttons. You might be able to do <html:cancel value="ButtonText"/> for a button that skips validation. Just do not declare the property attribute of the tag because the tag's default value is what triggers this functionality. I've haven't tried this but it sounds like a fun idea.


A good workman is known by his tools.
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
The trouble with radio buttons is that they don't send anything to the server if they're unchecked. The reset() method gets around this problem by always setting a default value for the form's properties.


Thanks!! But i am a bit confused on this. The purpose of the validation on a required field is to check to see if it's empty. If nothing is sent to the server because no radio button is selected. shouldn't the validator handle this properly and inform the user that a field is missing instead of let it pass through?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Let's say you have a series of three radio buttons, all mapped to the "color" property, with one returning a value of "red", another "blue", and another "greeen". If none of the buttons is checked, no color parameter will be submitted to the server at all.

When Struts populates the form bean, the setter for color does not get called, so the property is null. I'm not sure why Struts doesn't consider a value of null to be in violation of the "required" condition. It appears to be looking for the value "". Therefore, in your reset() method, you should set the value of color to "".

The above occurs if the form is in request scope. If it's in session scope, it retains the value it had before, and is not changed. In this case it's even more critical that you reset the value of color in the reset() method.

That's why for check boxes and radio buttons, the manual recommends that you always set an unchecked value for the corresponding properties in the reset() method of the form.
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
Marc,
thanks!
2. If I understand correctly, your suggestion is to set some parameter in the form and then based on its value from actionform.validate() I might or might not call super.validate()? right?
what if I use a dynaValidatorForm?

3. Is there anyway that I can mimic cancel button?
this is what the rendered code of cancel looks like
<input type="submit" name="org.apache.struts.taglib.html.CANCEL" value="cancel">
[ March 18, 2005: Message edited by: jonathan Greens ]
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
Merril,
thanks I will try the reset() approach
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to disable struts validation