trouble with h:selectOneMenu
waltc May 22, 2010 10:34 PMI 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