Announcement Announcement Module
No announcement yet.
Validation of checkbox using Commons validation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation of checkbox using Commons validation

    We are using commons validation from spring modules and works great for text fields. But, when we use it for checkboxes, it doesn't seem to work.

    In the validation.xml, we have the following entry
    <field property="agreedLegalPolicy" depends="required">
    <msg name="required" key="error.legalnotchecked" />

    In our command object the agreedLegalPolicy is a boolean field.

    Tracing the code using a debugger, it looks like the required check always succeed since the boolean is initialized to false when the checkbox is not checked.

    Any thoughts on how this should work will be appreciated. The alternative I am considering is to use a custom validation class or override the onBindAndValidate of the form controller to perform custom validation.


  • #2
    I'm sure you've found a workaround in the past 3 years, but for the sake of others who find this thread:

    The best solution I found was to create a custom Commons Validator validator for "booleanValue." You supply either "true" or "false" as a var to the validation rule, and then it checks to make sure your field is the same value.