JSF issue - UISelectItems

Strange error received from compiler:

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

So, if he was expecting UISelectItems and found UISelectItems, then where is the error?

My JSP implementation:

 <h:selectOneMenu id="siachoice" value="#{dbSelectBean.currentOption}"> <f:selectItems value="#{dbSelectBean.dbs}" /> </h:selectOneMenu> 

Method where I set the UISelectItem for UISelectItems:

 private UISelectItems populateDatabases(String databaseString) { UISelectItems selects = new UISelectItems(); List<UISelectItem> result = new ArrayList<UISelectItem>(); StringTokenizer tokeniz = new StringTokenizer(databaseString, GlobalConstants.DELIMITER); while(tokeniz.hasMoreTokens()){ String tempDB = tokeniz.nextToken(); UISelectItem item = new UISelectItem(); item.setItemValue(tempDB); item.setItemLabel(tempDB); result.add(item); } selects.setValue(result); return selects; } 

Then, of course, I set it to the bean dbs variable.

reference

+4
source share
4 answers

You should return Collection from javax.faces.model.SelectItem

  List list = new ArrayList ();
 list.add (new SelectItem (value, label));

+4
source

<f:selectItems value="#{bean.items}" /> expects one of the following values:

 public SelectItem[] getItems() {} public List<SelectItem> getItems() {} public Map<String, Object> getItems() {} 

Commonly used is List<SelectItem> .

Edit : as a response to the comment: UISelectItem represents the <f:selectItem> component. The same goes for UISelectItems and <f:selectItems> . For instance.

 <f:selectItem binding="#{bean.selectItem}" /> <f:selectItems binding="#{bean.selectItems}" /> 

which are related as

 private UISelectItem selectItem; private UISelectItems selectItems; // +getter +setter 

this way you can programmatically control the components - for all the rest of the UIComponent .

+4
source
 <h:form> <h:selectOneListbox size="5" > <f:selectItems value="#{userManager.Test()}" /> </h:selectOneListbox> </h:form> 

 import javax.faces.model.SelectItem; import tn.com.ttnproject.entity.*; @Name("userManager") @Scope(ScopeType.CONVERSATION) public class UserManager { public List <SelectItem> listAllUsersNames; SelectItem element; public List<SelectItem> Test(){ listAllUsersNames = new ArrayList<SelectItem>(); for (int i=1;i<=10;i++) { element=new SelectItem( new Integer(i), i+".00 euros", "Produit Γ  "+i+".00 euros"); listAllUsersNames.add(element); } return listAllUsersNames; } } 
+1
source

Problem UISelectItem is a cluster of components, so it must be associated with the jsf tag with the binding attribute. If you want to have pure values, you must use the SelectItem (s) classes.

0
source

All Articles