Qadir Hussain
Qadir Hussain

Reputation: 1263

javax.faces.FacesException: Target model Type is no a Collection or Array

When submitting a JSF form, I'm getting the below 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?

Upvotes: 3

Views: 11845

Answers (2)

Marcelo Rebouças
Marcelo Rebouças

Reputation: 699

My solution was: I removed the attribute "dtSubItem" from the tag process of the <p:commandButton> tag and all works normally. The command button was submitting the datatable on the submit event.

Worked on the first request, but at the second the error emerged, when datatable was populated.

<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>	

Upvotes: 0

BalusC
BalusC

Reputation: 1108632

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:

Upvotes: 7

Related Questions