0

i am trying to use c foreach with hashmap or table in jsf 2.0 but it is not working so i wrote one simple code like this still this one is not working .... please help where i am missing...

<body>
<f:view>
    <c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
        <c:out value="#{i}" /> 
    </c:forEach>
</f:view>

and output for this i am getting like this ..

#{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} 
zytham
  • 613
  • 1
  • 12
  • 27

3 Answers3

6

EL will fail in JSTL tags in a JSF2 webapp when you're using the ancient and EOL'ed JSTL 1.0 for some reason.

Make sure that you've installed at least JSTL 1.1 or 1.2. JSTL 1.2 is recommended. First remove jstl.jar and standard.jar from your /WEB-INF/lib, then download jstl-1.2.jar and drop it in /WEB-INF/lib. Finally make sure that you set the XML namespace as follows (with the /jsp path in the URI!):

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

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

Use $ instead of #

<c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
        <c:out value="${i}" /> 
</c:forEach>

<c:forEach> is from JSTL, with JSF you should use <ui:repeat> as Luiggi commented

jmj
  • 237,923
  • 42
  • 401
  • 438
  • hey it is not working ... even if i replaced with # .... it is having some problem .. can u please tell me whether i should use xhtml template or something to make it work ... i tried all thing but it is not working ... – zytham Jul 16 '12 at 08:11
  • i am getting one error like " According to TLD or attribute directive in tag file, attribute value does not accept any expressions ".. – zytham Jul 16 '12 at 08:14
  • after rending in browser it is displaying like this JSTL Simple Conditional Execution Example – zytham Jul 16 '12 at 08:17
1

you are not specifying what exactly does not work when you use it with your map... did you try setting the items of your map/table within the foreach:

<c:forEach items="#{myMap}" var="item">             
  <h:outputText value="#{item.key}" />
  <h:outputText value="#{item.value}" />
</c:forEach>
Korgen
  • 5,191
  • 1
  • 29
  • 43
  • i used the same thing to print key and value pair but is not displaying any thing ... i am using .xhtml template. in page source i found that code is not rending properly in browser .. it is displaying block of code simply.. – zytham Jul 16 '12 at 07:59
  • yes .. others are working fine like "graphicimage" and "outputtext" all are working fine .. – zytham Jul 16 '12 at 08:19
  • what about other jstl tags like or sth. like that? – Korgen Jul 16 '12 at 08:43
  • hey i am adding what is HTML output .. JSTL Simple Conditional Execution Example

    – zytham Jul 16 '12 at 09:52
  • i think it is not rendering properly..what i have to for that .. i am using .xhtml Extesion ?? whether it is wrong ?? – zytham Jul 16 '12 at 09:53
  • My code sample is this : JSTL Simple Conditional Execution Example

    ${nameMap.key}

    – zytham Jul 16 '12 at 10:09