映射为rich:pickList的支持属性

时间:2013-05-15 13:31:18

标签: java jsf jsf-2 richfaces seam

我想使用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>

支持bean:

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
谁知道它到底发生了什么?

1 个答案:

答案 0 :(得分:1)

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

接下来,<ui:repeat>目前不支持迭代Set,因此要么创建一个返回List的帮助器getter,要么创建一个自定义EL函数,或者使用{ {1}}方法。

例如,后者将如下所示:Set#toArray()。有关其他选择,请查看有关此主题的答案,以及已在Stack Overflow上提出并回答的问题。