0

我想Map<String, List<Object>>用作rich:pickList 的后备属性,如下所示:

       <ui:repeat value="#{bean.selectedMap.entrySet" var="entry"} >
        <rich:pickList value="#{entry.value}" var="list" >
            <f:selectItems value="#{bean.getAll}" />
            <f:converter converterId="myBeanConverter" />
         </rich:pickList>
       </ui:repeat>

后备豆:

public class MyBean {
private Map<String, List<String>> myList;
...
getters/setters for myList
}

问题是我仍然遇到这个异常:

15:19:16,583 SEVERE [info.fingo.salutor.exception.CustomExceptionHandler] (http--127.0.0.1-8080-4) Critical Exception!: javax.faces.FacesException: ModelType (class java.lang.Object) must be either an Array, or a Collection
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:84) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

Caused by: javax.faces.FacesException: ModelType (class java.lang.Object) must be either an Array, or a Collection
    at org.richfaces.renderkit.SelectManyHelper.getConvertedValue(SelectManyHelper.java:332) [richfaces-components-ui-4.2.2.Final.jar:4.2.2.Final]
    at org.richfaces.renderkit.SelectManyRendererBase.getConvertedValue(SelectManyRendererBase.java:108) [richfaces-components-ui-4.2.2.Final.jar:4.2.2.Final]
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIInput.validate(UIInput.java:960) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIInput.processValidators(UIInput.java:698) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:532) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.facelets.component.UIRepeat.processValidators(UIRepeat.java:766) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIForm.processValidators(UIForm.java:253) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.7-jbossorg-2.jar:]
    ... 39 more

有谁知道这是怎么回事?

4

1 回答 1

1

如果我们对未能正确关闭 EL 表达式( )视而不见,问题在于地图实例上}确实没有定义任何方法。getEntrySet因此,假设您的环境支持 EL 2.2,只需将函数调用()放在 EL 表达式的末尾,告诉 EL 这是一个方法调用。

接下来,<ui:repeat>目前不支持对 a 进行迭代Set,因此要么创建一个返回 a 的辅助 getter List,要么创建一个自定义 EL 函数,或者使用该Set#toArray()方法。

例如,后者看起来像:#{bean.selectedMap.entrySet().toArray()}. 对于另一种选择,请查看有关此主题的答案,这些问题已在 Stack Overflow 上提出并回答。

于 2013-05-15T14:13:34.047 回答