Announcement Announcement Module
Collapse
No announcement yet.
Checkboxes with a false value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checkboxes with a false value

    I have a Roo generated jspx form with a checkbox as follows:
    <field:checkbox disableFormBinding="true" field="isCompleteTrue" id="f_com_novexinc_orderhawk_shrink_ShrinkMaster_i sCompleteTrue" z=""/>
    When the box is checked, the controller gets the request parameter as:
    &isCompleteTrue=on
    When it is unchecked, the parameter is missing, and I get:
    Required Boolean parameter 'isCompleteTrue' is not present

    How can I modify the @RequestParam("isCompleteTrue") Boolean isCompleteTrue,
    in the controller parameters to make this optional?

    Or, more simply put, should I not get:
    &isCompleteTrue=off
    when the checkbox is unchecked?

  • #2
    This is how your form is submitted by your browser unfortunately. Have you tried using a primitive boolean type for the field member. This should be defaulting to false in your controller.

    Comment


    • #3
      I eventually found the solution to this elsewhere. Using @RequestParam makes this parameter required.

      To handle optional parameters, you must do the following:
      Add HttpServletRequest req to the parameter list for your controller method, and then, inside the method:
      Code:
      Boolean isCompleteTrue = null;
      if (null != req.getParameter("isCompleteTrue"))
      {
              isCompleteTrue = new Boolean((req.getParameter("isCompleteTrue").equals("on")) || (req.getParameter("isCompleteTrue").equals("true")));
      }
      Last edited by Andrew Swan; Aug 7th, 2011, 09:28 PM. Reason: Added code tags around code snippet

      Comment

      Working...
      X