2 Replies Latest reply on Mar 24, 2010 7:15 PM by Zaheer Ahmed

    Help needed in selectOneMenu

    Zaheer Ahmed Novice

      Hi

      Can anyone please help with my code,  I'm trying to populate selectOneMenu list from bean I'm getting the value but it's not working the way I want it to work.  I'm getting selected one value from bean file but I want to display two further more values so the user can update if wishes.  This is my code so far not quite sure how to go about it?

       

      thanks

      Zed

       

      <c:choose>
      <c:when test="${param.update == 'true'}" >  
      <td><h:selectOneMenu  id="type" value="#{bean.selectedEvent.eventTypeCode}" required="true">
      <c:choose>
      <c:when test="#{bean.selectedEvent.eventTypeCode == 'APPT'}" >
      <f:selectItem itemValue="#{bean.selectedEvent.eventTypeCode}" itemLabel="Appointment" />
      </c:when></c:choose>
      <c:choose>
      <c:when test="#{bean.selectedEvent.eventTypeCode == 'MEET'}">
      <f:selectItem itemValue="#{bean.selectedEvent.eventTypeCode}" itemLabel="Meeting" />
      </c:when></c:choose>
      <c:choose>
      <c:when test="#{bean.selectedEvent.eventTypeCode == 'ANNV'}">
      <f:selectItem itemValue="#{bean.selectedEvent.eventTypeCode}" itemLabel="Anniversary" />
      </c:when></c:choose>
      </h:selectOneMenu></td>
      </c:when>
      </c:choose>

        • 1. Re: Help needed in selectOneMenu
          Nick Belaevski Master

          Hi Zed,

           

          Looking at the code posted, it seems to me that code block with all the nested c:choose/c:when can be replaced by:

           

          <f:selectItem itemValue="#{bean.selectedEvent.eventTypeCode}" itemLabel="#{bean.selectedEvent.eventTypeLabel}" />
          

           

          or

           

          <f:selectItem itemValue="#{bean.selectedEvent.eventTypeCode}" itemLabel="#{bean.eventTypeLabelsMap[bean.selectedEvent.eventTypeCode]}" />

           

          Also it is better to remove logic from your view as possible and use beans. JSF provides special attributes that you can use: "rendered" instead of <c:if>, <f:selectItem> with its "value" attribute, etc.

          • 2. Re: Help needed in selectOneMenu
            Zaheer Ahmed Novice

            Thanks for your reply Nick I'm gonna have a go at it.

             

            Zed