javax.faces.FacesException:目标模型类型不是集合或数组 [英] javax.faces.FacesException: Target model Type is no a Collection or Array
问题描述
提交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);
}
另请参见:
- 如何在使用JSF的情况下,从后端bean中的h:selectManyListbox获取所有选定的值?
- How to get all the selected values from h:selectManyListbox in the backend bean in case of JSF?
See also:
这篇关于javax.faces.FacesException:目标模型类型不是集合或数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!