• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

struts validation framework and checkboxes

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am using validator framework and am trying to validate a checkbox has been checked - ive tried required and validwhen checking for != null but neither seems to work - any ideas?
cheers
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem with checkboxes is that if the checkbox is selected or ON then you get the parameter or you dont get anything. One way to work around is to get the parameter from the request, if the parameter is present then the checkbox is selected or if the parameter is absent thenthe checkbox is unchecked. Another way is to use the reset() method of the ActionForm class.
 
rob harvey
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i use the rest to reset it to false when need be - how can i access the request parameter in the validator xml? ive tried required as per earlier suggestions but it doesnt seem to work?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

create a JavaScript function that will be called by the onsubmit event of the <html:form> tag.

The function would look something like this:


This forces the checkbox to return a value of either true or false. you can then use validation not to allow a value of false.
 
reply
    Bookmark Topic Watch Topic
  • New Topic