How to access Map in JSF

萝らか妹 提交于 2019-12-08 05:09:29

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>

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.

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">

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

See also:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!