JSTL c:forEach is not working in Facelets
Asked Answered
A

2

6

I have a file called test.xhtml i am trying to access a hash map using foreach in Facelets, but it is not displaying key value pair my code is as follows. How is this caused and how can I solve it?

    <html xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
    <title>JSTL Simple Conditional Execution Example</title>
</head>
<h:body>
    <f:view>
        <c:forEach var="nameMap" items="${specificationAutogege.details}">
            <p> ${nameMap.key}</p>
        </c:forEach>
    </f:view>
</h:body>

Is it possible to use JSTL in Facelets?

The HTML output is rendered as follows:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core">
<head>
    <title>JSTL Simple Conditional Execution Example</title>
</head>
<body>
    <c:forEach var="nameMap" items="{Versnellingsk=A very long text come here, Kleur=ZWART Two, Model=3008, Carrosiere=5 deures MPV, A very long text come here=Date Here, BrandShoert=E, Type=3008 Hybrid4 2.0 HDi, Merk=Peugeot, Bowjaar=2011 Shortgate}" varstatus="true">
        <p/>
    </c:forEach>
</body>
</html>
Arnitaarno answered 16/7, 2012 at 10:23 Comment(2)
i am just trying to display key only .. but that one is not working. but same is working when i am using JSP template having .JSP extesnion .Arnitaarno
are you using JSF2 ? try using this namespace xmlns:c="http://java.sun.com/jsp/jstl/core"Animalism
O
12
xmlns:c="http://java.sun.com/jstl/core"

This JSTL XML namespace URI is specific to Facelets 1.x. JSF 2.x ships with Facelets 2.x which has a different JSTL XML namespace URI:

xmlns:c="http://java.sun.com/jsp/jstl/core"

Since JSF 2.2 new XML namespace domain was introduced to remove old sun.com domain.

xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"

See also:

Orjonikidze answered 16/7, 2012 at 13:43 Comment(0)
H
-1

The xhtml extension suggests you're using JSF2 rather than JSF, hence you need to switch from using the ${} notation to #{} notation.

Hope that helps.

Hoarse answered 9/10, 2014 at 16:4 Comment(1)
Both behave exactly the same when using JSF2 Facelets. Moreover, Facelets can be used together with JSF1, it only needs to be installed and configured separately.Orjonikidze

© 2022 - 2024 — McMap. All rights reserved.