3

提交 JSF 表单时,出现以下异常:

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

这是如何引起的,我该如何解决?

4

2 回答 2

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

于 2013-02-04T11:58:43.103 回答
0

process我的解决方案是:我从标签的 标签中删除了属性“dtSubItem” <p:commandButton>,一切正常。命令按钮在提交事件上提交数据表。

处理第一个请求,但在第二个请求出现错误时,填充数据表。

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

于 2019-04-09T13:11:05.317 回答