如何在JSF中访问Map [英] How to access Map in JSF

查看:206
本文介绍了如何在JSF中访问Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用C:foreach来访问jsf中的地图。但我无法使用#符号访问jsf中的地图。但我可以使用$符号访问它。但是我需要访问使用jsf组件显示h:outputtext.My示例代码是

I have try to access the map in jsf using C:foreach.But i can't access that in jsf by using"#" symbol.But i can access it using "$" symbol.But i need to access to displayed using jsf component h:outputtext.My sample code is

h:form binding="#{MapInJsf.initForm}">
                <c:forEach items="#{MapInJsf.nameMap}" var="nameMap">
                    <%--<li>${nameMap.key}</li>--%> I cann access it
                    <%--<h:outputText value="#{nameMap}"/>--%>
                    <h:outputText value="Name2 : #{nameMap.key}"/>
                   <h:outputText value="Last Name1 : #{nameMap.value}"/>
                </c:forEach>
            </h:form>

我做错了什么以及如何访问?我的Ref链接是
JSF组件的动态值绑定
请帮助我。

what i do wrong and how can i access that?My Ref link is Dynamic value binding of JSF component Please help me.

推荐答案

这仅适用于使用JSP 2.1或更高版本(Servlet 2.5或更高版本)的情况。在JSP 2.0或更早版本(Servlet 2.4或更早版本)上,无法通过延迟EL #{} c:forEach 变量code>。延迟的EL #{} 最初是JSF 1.0的一部分,后来在JSF 1.2发布时才被集成到JSP 2.1中。但是,您应该能够使用标准EL $ {}

This will only work when you're using JSP 2.1 or newer (Servlet 2.5 or newer). On JSP 2.0 or older (Servlet 2.4 or older), it is not possible to reference the c:forEach variable by deferred EL #{}. The deferred EL #{} was namely initially part of JSF 1.0 and was only later integrated in JSP 2.1, around the time JSF 1.2 was released. You should however be able to use standard EL ${}.

<c:forEach items="${MapInJsf.nameMap}" var="nameMap">
    <h:outputText value="Name2 : ${nameMap.key}"/>
    <h:outputText value="Last Name1 : ${nameMap.value}"/>
</c:forEach>

但是你无法将它绑定到 UIInput 组件,如< h:inputText> ,因为 $ {} 表示法仅调用bean getter,不是setter。

But you won't be able to bind it to an UIInput component like <h:inputText> since the ${} notation only calls bean getter, not setter.

如果您正在运行servlet 2.5兼容容器(如Tomcat 6.0及更高版本),那么您需要确保 web根据Servlet 2.5声明.xml 。即根声明必须如下:

If you're running a servlet 2.5 compatible container (like Tomcat 6.0 and up), then you need to ensure that your web.xml is declared as per Servlet 2.5. I.e. the root declaration must be as follows:

<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="YourWebAppID"
    version="2.5">

只有这样你才能使用延期EL #{} 关于JSP标签,如JSTL。

Only then you will be able to use deferred EL #{} on JSP tags like JSTL.

  • Java/JSP article on The Unified Expression Language

这篇关于如何在JSF中访问Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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