Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSTL c:forEach is not working in Facelets

Tags:

jsf

jstl

facelets

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>
like image 296
zytham Avatar asked Jul 16 '12 10:07

zytham


1 Answers

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:

  • Our JSTL wiki page
  • Which XML namespace to use with JSF 2.2
like image 88
BalusC Avatar answered Sep 26 '22 19:09

BalusC