Javax.faces.FacesException: Target Model Type is not Collection or Array
When submitting a JSF form, I get the following exception:
Caused by: javax.faces.FacesException: Target model Type is no a Collection or Array
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:388) [:2.0.3-]
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:125) [:2.0.3-]
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:311) [:2.0.3-]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023) [:2.0.3-] at javax.faces.component.UIInput.validate(UIInput.java:953) [:2.0.3-]
at javax.faces.component.UIInput.executeValidate(UIInput.java:1204) [:2.0.3-]
at javax.faces.component.UIInput.processValidators(UIInput.java:693) [:2.0.3-]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-]
at javax.faces.component.UIForm.processValidators(UIForm.java:240) [:2.0.3-]
at org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439) [:3.3.1.GA]
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238) [:3.3.1.GA]
at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455) [:3.3.1.GA]
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72) [:2.0.3-] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
... 42 more
How is this caused and how can I solve it?
source to share
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 have a component UISelectMany
in the view, such as <h:selectManyMenu>
or <h:selectManyListbox>
, whose value is not associated with a collection or an array. It is not right. Its value must be bound to a collection (for example List<Entity>
) or an array (for example Entity[]
), since a component can retrieve multiple presented values.
Here's a start example of what the correct one looks like <h:selectManyMenu>
, assuming you are using printed items String
:
<h:selectManyMenu value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</h:selectManyMenu>
<h:commandButton value="submit" action="#{bean.submit}" />
from
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:
source to share
My solution was: I removed the "dtSubItem" attribute from the process
tag tag <p:commandButton>
and everything works fine. The command button was sending data to the submit event.
Worked on the first request, but on the second there was an error when the datatable was full.
<div class="ui-g-12 ui-md-6 ui-lg-2">
<div class="espacoCampo">
<p:outputLabel value="" />
<p:commandButton actionListener="#{managedBean.adicionarSubItemPanel(item)}"
update="dtSubItem"
title="Clique aqui para adicionar SubItem"
icon="fa fa-plus"
value="Adicionar"
process="@this dtSubItem cadSubItens"
iconPos="right"
>
</p:commandButton>
</div>
</div>
<p:dataTable var="subItem" id="dtSubItem" emptyMessage="Sem registros adicionados" value="#{item.btpResolucaoItemSubitemList}">
...
</p:dataTable>
source to share