• 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

how to disable struts validation

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merril,
thanks I will try the reset() approach
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic