2 Replies Latest reply on Sep 14, 2009 6:40 PM by Roger Lee

    Getting selected value from h:selectOneMenu

    Roger Lee Apprentice
      I am using Seam 2.2.0 GA, deployed on JBoss 4.2.3 GA.
      I am able to populate a h:selectOneMenu with the data from a (MySQL) table, but I can’t for the life of me get the selected value from the drop down menu back to my stateless session bean (SLSB), I’ve Google’d till the cows come home!

      The “entity” is always null in my SLSB.

      XMTL;
      '
      <h:outputLabel for="devicesToTrack">Device to track</h:outputLabel>
                      <h:selectOneMenu id="devicesToTrack" required="true">
                          <s:selectItems value="#{devicesToTrackList}"
                          var="devicesToTrack"
                          label="#{devicesToTrack.devicesToTrackPK.deviceIdMobileNumber}"
                          itemValue="#{devicesToTrack}" 
                          noSelectionLabel="Please select"/>
                          <s:convertEntity/>
             
                          <a4j:support event="onchange" action="#{devicesToTrackBean.getDevicesToTrackCurrentLocation(devicesToTrack)}"/>
                         
                      </h:selectOneMenu>
                      <rich:message for="devicesToTrack">
                      </rich:message>
      '

      SLSB;

      '
      @In (required = false)
          private DevicesToTrack devicesToTrack;
         
          @Out
          private List <DevicesToTrack> devicesToTrackList;
         
          /**
           *
           */
          public DevicesToTrackBean() {
          }
         
          @SuppressWarnings("unchecked")
           @Factory("devicesToTrackList") 
          public void getDevicesToTrack() {
               final Query query = entityManager.createQuery(GET_DEVICES_TO_TRACK);
               query.setParameter(ONE, "rlee@notify.co.uk");
               
                devicesToTrackList = query.getResultList();
                log.info(">>>>> getDevicesToTrack devicesToTrackList size      = " + devicesToTrackList.size());
          }

          public void getDevicesToTrackCurrentLocation(Object o) {
          //public void getDevicesToTrackCurrentLocation() {
               //String s = (String) o;
               log.info(">>>>> getDevicesToTrackCurrentLocation o = " + o);
               devicesToTrack = (DevicesToTrack) o;
               log.info(">>>>> getDevicesToTrackCurrentLocation devicesToTrack = " + devicesToTrack);
               log.info(">>>>> getDevicesToTrackCurrentLocation devicesToTrack = " + devicesToTrack.getDevicesToTrackPK());
               
          }
      '

      Output in JBoss console;
      11:34:30,672 INFO  [DevicesToTrackBean] >>>>> getDevicesToTrack devicesToTrackList size         = 3
      11:34:30,734 INFO  [DevicesToTrackBean] >>>>> getDevicesToTrackCurrentLocation o = com.notifypinpoint.entity.DevicesToTrack@7ab991
      11:34:30,734 INFO  [DevicesToTrackBean] >>>>> getDevicesToTrackCurrentLocation devicesToTrack = com.notifypinpoint.entity.DevicesToTrack@7ab991
      11:34:30,734 INFO  [DevicesToTrackBean] >>>>> getDevicesToTrackCurrentLocation devicesToTrack = null