Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf javax.faces.FacesException:目标模型类型不是集合或数组_Jsf_Jsf 2 - Fatal编程技术网

Jsf javax.faces.FacesException:目标模型类型不是集合或数组

Jsf javax.faces.FacesException:目标模型类型不是集合或数组,jsf,jsf-2,Jsf,Jsf 2,提交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.rend

提交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
这是如何造成的,我如何解决

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
组件,如
,其值未绑定到集合或数组。这是不对的。它的值必须绑定到集合(如
列表
)或数组(如
实体[]
),因为组件可以检索多个提交的值

假设您使用的是
String
类型化项目,下面是一个正确的
的启动示例:

<h:selectManyMenu value="#{bean.selectedItems}">
    <f:selectItems value="#{bean.availableItems}" />
</h:selectManyMenu>
<h:commandButton value="submit" action="#{bean.submit}" />

private List selectedItems;//注意:列表,因此不是字符串!
私有列表可用项;
@施工后
公共void init(){
availableItems=Arrays.asList(“一”、“二”、“三”、“四”、“五”);
}
公开作废提交(){
System.out.println(“所选项目:+selectedItems”);
}
另见:

我的解决方案是:我从
标签的
过程
中删除了属性“dtSubItem”,所有功能都正常工作。命令按钮正在提交提交事件上的数据表

处理第一个请求,但在第二个请求中,当填充datatable时出现错误


...

仅用堆栈跟踪无法解决此问题-我们不知道哪个组件连接到哪个模型。创建一个显示此bug的简化代码示例。例如,一个JSF页面(和支持bean),其中只有实际代码中的一个和两个组件会导致出现相同的错误。(基本上,用你的代码开始删除与错误无关的内容。当你不能删除任何其他内容而不使错误不再出现时,这就是你的简化示例。)最好提供一些源代码,而不是这个1公里长的堆栈跟踪。我们只是看到,您没有在支持bean中为
selectMenu
组件提供正确的属性。
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);
}