1 Reply Latest reply on Jun 2, 2008 8:49 PM by infinity2heaven

    selectOneMenu Value not injected into seam managed bean.

    chadws

      I have a simple bean that provides users with a method of searching our staff members and determining their job title, building assignment, and general contact information. This form takes a firstname, lastname, and a location. I have the following working and it will find the correct profiles. However, in the working version if the users want to restrict the search to a specific location they have to enter the name of the location in a text field. I would like to present this as a drop down menu to remove the possibilty of spelling errors. The problem is that when I change the input method to a h:selectOneMenu the values are never injected into the profileSearchService.


      The Bean


      @Name("profileSearchService")
      @Scope(ScopeType.EVENT)
      public class ProfileSearchService {
      
              @In(create=true)
              private ProfileManagerLocal profileManager;
      
              @In(create=true)
              private LocationManagerLocal locationManager;
      
              @In(required=false)
              @Out(required=false)
              private String lastname;
      
              @In(required=false)
              @Out(required=false)
              private String firstname;
      
              @In(required=false)
              @Out(required=false)
              private String location;
      
              @Out(required=false)
              private List<Profile> profiles;
              
              public String findProfiles() {
                      Location lLocation = null;
                      if( location != null && location.trim().length() > 0) {
                              lLocation = locationManager.find(location);
                      }
                      if( isNotEmpty(lastname) || isNotEmpty(firstname) ) {
                              profiles =  profileManager.findProfiles(lastname, firstname, lLocation);
                      }
                      return null;
              }
      
              private boolean isNotEmpty(String aValue) {
                      boolean lIsNotEmpty = false;
                      if( aValue != null && aValue.trim().length() > 0 ) {
                              lIsNotEmpty = true;
                      }
                      return lIsNotEmpty;
              }
      
      }
      


      The Form


      <h:form>
              <label for="lastname" class="inline">Lastname:</label>
              <h:inputText value="#{lastname}" name="lastname" id="lastname"/><br />
      
              <label for="firstname" class="inline">Firstname:</label>
              <h:inputText value="#{firstname}" name="firstname" id="firstname"/><br />
      
              <label for="location" class="inline">Location:</label>
              <h:inputText value="#{location}" name="location" id="location"/><br />
      
              <br />
              <h:commandButton action="#{profileSearchService.findProfiles}" name="GO!">GO!</h:commandButton>
      
      </h:form>
      








      Whats more I have an entity converter that will convert the location to an Id and back to the Location object. If I configure the form to submit the Location instance i can debug the code and see my converter retrieving the submitted object, but when the findProfiles method of the profileSearchService is called the location field is still null? Does anyone know what I am missing that would keep a drop down menus submitted value from being injected properly?


      Changes to the Bean


      @In(required=false)
      @Out(required=false)
      private Location location;
      



      Changes to the form


       
              <h:selectOneMenu value="#{location}" name="location" id="location" converter="locationConverter">
                      <f:selectItem itemLabel="Any Location" />
                      <c:forEach var="locationOption" items="#{locationService.allLocations}">
                              <f:selectItem itemLabel="#{locationOption.name}"/>
                      </c:forEach>
              </h:selectOneMenu><br />
      



      I guess I am at a loss as to what I am doing wrong since this appears to be working and I am not seeing any errors displayed. Most of my errors have been from a lack of my understanding and I am hoping this one is an easy fix and someone can set me straight as well.

        • 1. Re: selectOneMenu Value not injected into seam managed bean.
          infinity2heaven

          You don't need a converter if it's just converting entity back to id. Seam has an inbuild converter called <s:convertEntity>


          Try this with seam controls.


          
          <h:selectOneMenu id="fof" value="#{location}">    
          
            <s:selectItems value="#{locationService.allLocations}" var="locationOption" label="#{locationOption.name}"/>
          
            <s:convertEntity/>                    
          
          </h:selectOneMenu>