2 Replies Latest reply on Apr 20, 2012 8:58 AM by anicapil

    How to put enum+string value in specific oreder in selectOneMenu.

    anicapil

      Hi!

      I want to pu 'All' at the bottom of dropDown. I have A Enum with two values 1) ModelText 2) SellingText and want to put "All" at the bottom.

      I can place "at the top with the help of noSelectionLabel="All" but not vice versa. Appriciate any help....  thousends of thanks.

       

      # this is my code : works but "All" comes on the top :-(

      <div>

                  <h:outputLabel for="textType" value="#{msg['informations.model.texttype.label']}"/>

                  <h:selectOneMenu id="textType" value="#{textStatusReportItem.textType}"

                                   label="#{msg['informations.model.texttype.label']}">

                      <s:selectItems value="#{textTypeList}" var="textType" label="#{textType.name}" noSelectionLabel="All"/>

                      <s:convertEnum/>

                  </h:selectOneMenu>

              </div>

       

      # i want to do like this...

       

      I refactored like this without success :-(

      <s:selectItems value="#{textTypeList}" var="textType" label="#{textType.name}"/>

      <f:selectItem itemLabel="ALL" itemValue=""/>

        • 1. Re: How to put enum+string value in specific oreder in selectOneMenu.
          serkan

          @Factory("myEnums")

          public List<String> getEnums() {     

                 List<String> result = new ArrayList<String>();

                  for(MyEnum m : MyEnum.values())

                      result.add(m.value());

           

                  result.add("All");         

          }

           

          <h:selectOneMenu value="#{yourBean.enumInString}"...>

              <s:selectItems value="#{myEnums}" .../>

          </h:selectOneMenu>

           

           

          public class YourBean {

             String enumInString;

           

             public MyEnum asEnum() {

               return "All".equals(enumInString) ? null : MyEnum.valueOf(enumInString);

             }

          }

          • 2. Re: How to put enum+string value in specific oreder in selectOneMenu.
            anicapil

            Thanks a lot Serkan. It s a nice solution.

             

            I solv it like this...

            I am just showing selected value..

            @Create

                public void create() {

                    textType = TextTypeEnum.MODEL_TEXT;

                }