javax.faces.FacesException: Target model Type is no a Collection or Array
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:388)
This exception indicates that you've an UISelectMany
component in the view such as <h:selectManyMenu>
or <h:selectManyListbox>
whose value is not been bound to a collection or array. This is not right. Its value must be bound to a collection (like List<Entity>
) or array (like Entity[]
), because the component can retrieve multiple submitted values.
Here's a kickoff example of how a proper <h:selectManyMenu>
look like, assuming that you're using String
typed items:
<h:selectManyMenu value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</h:selectManyMenu>
<h:commandButton value="submit" action="#{bean.submit}" />
with
private List<String> selectedItems; // Note: List<String> and thus NOT String!
private List<String> availableItems;
@PostConstruct
public void init() {
availableItems = Arrays.asList("one", "two", "three", "four", "five");
}
public void submit() {
System.out.println("Selected items: " + selectedItems);
}
See also:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…