3 Replies Latest reply on Dec 3, 2010 5:53 AM by mopper

    selectitems converter

    renegritsch

      I have a bound selectonelistbox with entries coming from <h:selectitems and a converter.

       

      The problem is, that the converter gets called and returns the correct formatted value (for example: 1.000.000,00), but

      the value shown in the selectonelistbox is the wrong one, coming from the selectitemlist.

      For inputfields the converter works fine.

       

       

      {code:xml}

      <h:selectOneListbox value="#{binding}" size="1" id="#{cid}">

           <f:selectItems value="#{x.selectItemList}" />

           <f:converter converterId="OurConverter"/>

           <f:attribute name="dpm" value="#{guiProperties}" />

           <f:attribute name="pattern" value="#{pattern}" />

           <a4j:support process="#{cid}" ajaxSingle="true" limitToList="true" event="onchange" reRender="#{trigger.getReRenderList(cid,'sol_',guiProperties)}"/>

      </h:selectOneListbox>

      {code}

       

       

      {code}

      public final List<SelectItem> getSelectItemList() {

              final List<SelectItem> selectItems = new ArrayList<SelectItem>(listValues.size());

              for(final Object obj : someListValues) {

                  selectItems.add(new SelectItem(obj));

              }

              return selectItems;

      }

      {code}

        • 1. Re: selectitems converter
          mopper

          My first idea would be that a <h:selectOneListBox/> does not display the value attribute of your SelectItems, but the label attribute. You might want to try setting the labels on the SelectItems you create in your getSelectItemList() method.

          • 2. Re: selectitems converter
            renegritsch

            Sure, then it works fine, but i do not want to have the same code as in the converter or called it twice.

            For my opinion it´s a bug, because what for do i need the converter then?

            • 3. Re: selectitems converter
              mopper

              The converter is not meant to format your value in a nice readable format here. It is needed to convert from your object to a String value and back. Your <h:selectOneListBox/> will end up as a html <select/> with a bunch of <option value="foo" label="bar"/> elements. So when you submit your values, it needs the converter to get the object that corresponds with the value of the selected <option/>. The SelectItem list is used to render the component, but when the user submits, it needs the converter to be able to convert the string value back into an object.

               

              It would probably be better to format the label in the method where you create the the list of SelectItems, and just leave the value unformatted. Then you do not need the formatting code in your converter.