javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-904

h:selectBooleanCheckbox ignores submittedValue

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2_11
    • Fix Version/s: 1.2_13-b01
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      (Version i am using is actually 1.2_11 but that isn't on the list of versions)

      h:selectBooleanCheckbox ignores the submittedValue. This means if you have a
      commandButton with immediate=true, all fields will render with the previous
      (submittedValues) except checkboxes.. OOPPSSS!! Big boo boo.

      If you look at CheckboxRenderer you will see that in getEndTextToRender() it
      calls ((UISelectBoolean) component).isSelected() to determine if the checkbox is
      checked.

      Comparing this logic it how all other basic html renders work, if you look at
      HtmlBasicRenderer you will see it uses the getCurrentValue(..) to get the value
      rendered in the input field, and getCurrentValue takes submittedValue into
      account. (Other components like SelectManyCheckboxListRenderer also pay
      attention to submittedValue.)

      Though untested the following code should fix the issue. Put it in place of
      CheckboxRenderer.getEndTextToRender:
      =============================
      @Override
      protected void getEndTextToRender(FacesContext context,
      UIComponent component,
      String currentValue) throws IOException {

      ResponseWriter writer = context.getResponseWriter();
      assert(writer != null);
      String styleClass;

      writer.startElement("input", component);
      writeIdAttributeIfNecessary(context, writer, component);
      writer.writeAttribute("type", "checkbox", "type");
      writer.writeAttribute("name", component.getClientId(context),
      "clientId");

      if ( isSelected(context, component) )

      { writer.writeAttribute("checked", Boolean.TRUE, "value"); }

      if (null != (styleClass = (String)
      component.getAttributes().get("styleClass")))

      { writer.writeAttribute("class", styleClass, "styleClass"); }

      RenderKitUtils.renderPassThruAttributes(writer,
      component,
      ATTRIBUTES);
      RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);

      writer.endElement("input");

      }
      public boolean isSelected(FacesContext context, UIComponent component) {
      if (component instanceof UIInput) {
      Object submittedValue = ((UISelectBoolean) component).getSubmittedValue();
      if (submittedValue != null)

      { return Boolean.parseBoolean((String)submittedValue); }

      }
      return ((UISelectBoolean) component).isSelected();
      }

      =============================

        Issue Links

          Activity

          Hide
          Ryan Lubke added a comment -

          Started...

          Show
          Ryan Lubke added a comment - Started...
          Hide
          Ryan Lubke added a comment -

          Created an attachment (id=822)
          Proposed Changes (ver 1)

          Show
          Ryan Lubke added a comment - Created an attachment (id=822) Proposed Changes (ver 1)
          Hide
          Ed Burns added a comment -

          r=edburns

          Show
          Ed Burns added a comment - r=edburns
          Hide
          Ryan Lubke added a comment -

          Changes applied to 1.2 and 2.0.

          Show
          Ryan Lubke added a comment - Changes applied to 1.2 and 2.0.
          Hide
          Manfred Riem added a comment -

          Closing issue out

          Show
          Manfred Riem added a comment - Closing issue out

            People

            • Assignee:
              Ryan Lubke
              Reporter:
              drtog16
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: