3 Replies Latest reply on Mar 9, 2007 5:43 AM by pmuir

    h:selectManyCheckbox and enums          

    stu2

      I'm trying to populate a group of checkboxes from enum values. I've gotten it working so that it displays properly (all checkboxes properly appear) but I get a converter exception when I submit the form. I wasn't able to find any examples of selectMany anything in the example apps, so forgive me if this is a basic question!

      Anyway, here's the exception I'm seeing:

      [ExceptionFilter] exception root cause
      java.lang.NullPointerException
       at org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.getConvertedUISelectManyValue(_SharedRendererUtils.java:147)
       at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUISelectManyValue(RendererUtils.java:673)
       at org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.getConvertedValue(HtmlCheckboxRendererBase.java:299)
       at javax.faces.component.UISelectMany.getConvertedValue(UISelectMany.java:326)
       at javax.faces.component.UIInput.validate(UIInput.java:349)
       at javax.faces.component.UISelectMany.validate(UISelectMany.java:315)
       at javax.faces.component.UIInput.processValidators(UIInput.java:183)
       at javax.faces.component.UIForm.processValidators(UIForm.java:70)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
       at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:146)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
      


      My SFSB looks like this (only relevant bits included):

       private ValidationCategory [] validationCategories;
      
       public ValidationCategory [] getValidationCategories() {
       return validationCategories;
       }
      
       public ValidationCategory [] getAllValidationCategories() {
       return ValidationCategory.values();
       }
      
       public void setValidationCategories(ValidationCategory [] validationCategories) {
       System.out.println("Setting val categories. Size is " + validationCategories.length);
       this.validationCategories = validationCategories;
       }
      


      And the facelets section for the form is this:

       <h:form id="productTypeForm">
       <h:selectManyCheckbox id="productTypes" value="#{feedMapping.validationCategories}">
       <s:selectItems value="#{feedMapping.allValidationCategories}"
       var="item" label="${item.name}" />
       </h:selectManyCheckbox>
       <div>
       <h:commandButton value="Continue"
       action="#{feedMapping.selectProductTypes}">
       <s:conversationId />
       </h:commandButton>
       </div>
       </h:form>
      


      I've tried several permuations of how to represent the selected values: as a List and in this case as an [] since I found a JSF forum post saying this was how it worked.

      s:selectItems is supposed to automatically register a converter for Enums, and it seems to be working for rendering the group. But can anyone suggest how I could capture the selected results?

      Thanks!

        • 1. Re: h:selectManyCheckbox and enums
          stu2

          I now have a string [] receiving the checkbox values, so the previous post's bean looks like this:

           private String [] validationCategories;
          


          And the page renders properly, showing all of the checkboxes. If I don't check any and click "Continue", the button's listener gets called, the value method gets called (setting 0 selections of course)

          <h:selectManyCheckbox id="productTypolios" value="#{feedMapping.validationCategories}">
          


          And all looks well. The moment I check any boxes though, it's as if the apply model values phase is never hit - nothing in the bean is called at all though. And I struggling with how to debug this.

          So, what I'd prefer is to get suggestions on how I can figure it out myself. I'm a JSF newbie, and though I'm reading everything I can get my hands on, some of this stuff is a little bumpy at first.

          Thanks!

          • 2. Re: h:selectManyCheckbox and enums
            pmuir

            s:selectItems doesn't register any converters. You need to put a <s:convertEnum /> on it

            Try adding an h:messages to your page and see where the error is ocuring.

            • 3. Re: h:selectManyCheckbox and enums          
              pmuir

              yeah. s:selectItems should work fine for a selectMany.

              http://jira.jboss.com/jira/browse/JBSEAM-1014