3 Replies Latest reply on Jun 7, 2010 12:31 PM by shravanou

    trouble with h:selectOneMenu

    waltc

      I am hoping this is an idiot simple answer, I've been working on this for days.


      I am trying to put up a selectOneMenu dropdown which will be populated in my bean.
      This is running under seam 2.2 in jboss 5.1 GA


      The xhtml segment is as follows:




                     <s:decorate id="monthChoice" template="layout/display.xhtml">
                          <ui:define name="label">Month</ui:define>
                          <h:selectOneMenu id="monthList"  value="#{QueryPerformanceSheet.month}">
                               <f:selectItems value="#{QueryPerformanceSheet.monthList}"></f:selectItems>
                          </h:selectOneMenu>
                     </s:decorate>
      



      With this I get the following error:


      Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(monthList). Found null.


      In the component list is the following:






          <HtmlDecorate element="div" enclose="true" id="monthChoice" rendered="true" template="layout/display.xhtml" transient="false">
      
              <div class="prop"> <span class="name">
      
              Month
      
              </span> <span class="value">
      
              <HtmlSelectOneMenu disabled="false" id="monthList" immediate="false" localValueSet="false" readonly="false" rendered="true" required="false" transient="false" valid="true" value="">
      
                  <UISelectItems id="j_id29" rendered="true" transient="false"/>
      
              </HtmlSelectOneMenu>
      
              </span> </div>
      
          </HtmlDecorate>
      
      
      
      




      This error occurs right after the getMonth() method of my bean is called, it returns an empty string. I am confused why the control would be driving getMonth when it should be driving setMonth after an item is selected.


      The very odd thing is if I change f:selectItems to f:selectItem it actually gets farther, but then complains that it was expecting an item of type SelectItem not a List.


      I've seen a gazillion examples that allegedly work just fine and am at a loss why I get that error.


      Here is the bean:



      mport java.util.ArrayList;
      import java.util.LinkedHashMap;
      import java.util.List;
      import java.util.Map;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.faces.model.SelectItem;
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.international.StatusMessages;
      import org.hibernate.validator.Length;
      
      @Name("QueryPerformanceSheet")
      
      public class QueryPerformanceSheetBean implements QueryPerformanceSheet {
           private static String monthQuery = "select distinct month(date) from Httpquery q";
           @Logger
           private Log log;
           @In
           StatusMessages statusMessages;
           @In
           protected EntityManager entityManager;
           private String value;
           @DataModelSelection
           @Out(required=false)
           private String month = "";
           @DataModel(scope = ScopeType.PAGE)
           private List<SelectItem>monthList;
           public void queryPerformance() {
                monthList = new ArrayList<SelectItem>();
                // implement your business logic here
                log
                .info("QueryPerformanceSheet.queryPerformance() action called with: #{QueryPerformanceSheet.value}");
                statusMessages.add("queryPerformance #{QueryPerformanceSheet.value}");
           }
      
           // add additional action methods
           public List<SelectItem> getMonthList() {
                return monthList;
           }
      
           public String getMonth() {
               return month;
           }
      
           public void setMonth(String month) {
                this.month = month;
           }
      
           @Length(max = 10)
           public String getValue() {
                return value;
           }
      
           public void setValue(String value) {
                this.value = value;
           }
      
           @Remove
           public void destroy() {
           }
      
           @SuppressWarnings("unchecked")
           @Factory("monthList")
           private void initForm() {
                ArrayList<String> tmp = 
                (ArrayList)entityManager.createQuery(monthQuery).getResultList();
                for (String month:tmp) {
                     SelectItem si = new SelectItem(month, month);
                     monthList.add(si);
                }
           }
      



      Thanks in advance,


      Walt

        • 1. Re: trouble with h:selectOneMenu
          waltc

          I have made progress.


          I have the two SelectOneMenu items emit @RequestParameters which seems to have made a big difference. I can break on the setter and see that they are being set but when the action button is pressed, which drives the setters in advance of the action method, by the time the method is called, the two request parameters are back to being null.


          I guess I am sufficiently weak in Seam to truly understand component life cycle. I tried setting the component's life to session and then to conversation. Neither scope made a difference.


          There has got to be something really simple I missed and would appreciate, greatly, a pointer.


          Thanks,


          Walt

          • 2. Re: trouble with h:selectOneMenu
            sean.tozer

            Have you tried using <s:selectItems> instead of <f:selectItems>? Just a shot in the dark there, but might give you some information. I tend to try to use the higher-level seam components when possible.

            • 3. Re: trouble with h:selectOneMenu
              Can you please try something like this 
              `ice:selectOneMenu id="report" value="\#{reportService.selectedReport}"     valueChangeListener="\#{reportService.reportSelected}"     partialSubmit="true"     required="true"     styleClass="iceSelReportName">                         <s:selectItems value="\#{reportService.reportList}"
                          var="report" label="\#{report.reportDesc}"               
                             noSelectionLabel="--- Please Select ---" />
              <s:convertEntity />                                        </ice:selectOneMenu>
              `

              Please let me know if this worked.

              Thanks!
              Kumar