2 Replies Latest reply on Jun 23, 2009 8:14 AM by oneworld95

    selectOneRadio with no items selected

    oneworld95

      Hi. How do you create a selectOneRadio item with no items selected? Here's the code:

      <h:selectOneRadio id="rdoPayrollEmployee" value="#{newemployee.payrollEmployee}">
       <f:selectItem itemLabel="Yes" itemValue="true"/>
       <f:selectItem itemLabel="No" itemValue="false"/>
      </h:selectOneRadio>


      I'd like neither yes or no to be selected when the page loads. Also, how do you format the radio buttons to go horizontally and take up as little space as possible? Thanks.

        • 1. Re: selectOneRadio with no items selected
          panky_p

          If your payrollEmployee is boolean change it to Boolean.
          your "#{newemployee.payrollEmployee}" should be null and not either true or false this way neither yes or no will be selected when the page loads.
          Use layout="lineDirection" on h:selectOneRadio to go horizontally

          • 2. Re: selectOneRadio with no items selected
            oneworld95

            Thanks, panky_p. That fixed all the issues! It makes sense now: In Java, wrapper datatype objects are better instead of primitive datatypes because wrapper types can be null while primitives cannot: http://www.freshsources.com/Mar99.html

            And boolean is a primitive type, whereas Boolean is the wrapper object. I made the following change in the action class for the form:

            private Boolean payrollEmployee = null; //don't use "boolean"


            The layout="lineDirection" fixed the other problem. In addition, the XHTML used CSS form layout, and the labels auto generated for the radio buttons were inheriting some unnecessary styling, which was throwing them all over the place.

            Thanks again, panky_p :D