javax.faces.FacesException:目标模型类型不是集合或数组 [英] javax.faces.FacesException: Target model Type is no a Collection or Array

查看:70
本文介绍了javax.faces.FacesException:目标模型类型不是集合或数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

javax.faces.FacesException: Target model Type is no a Collection or Array
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:388)

此异常表明您在视图中有一个UISelectMany组件,例如<h:selectManyMenu><h:selectManyListbox>,其值 not 未绑定到集合或数组.这个不对.它的值必须绑定到集合(如List<Entity>)或数组(如Entity[]),因为该组件可以检索多个提交的值.

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.

这是一个正确的<h:selectManyMenu>外观的启动示例,假设您使用的是String类型的项目:

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}" />

使用

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);
}

另请参见:

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆