3

Does anyone has any idea, why this code would work:

<h:outputText value="#{allocations[0].policyNumber}" />

and this code would work:

<c:forEach var="i" begin="1" end="5">
    <h:outputText value="aaa"/>
</c:forEach>

But this code would NOT work (nothing appears in GUI):

<c:forEach var="allocation" items="#{allocations}" >
    <h:outputText value="aaa"/>
</c:forEach>

I am using namespace "http://java.sun.com/jstl/core". allocations is a collection in java. I have tried everything I could think of and have no idea what to try next.

1 Answers1

5

The #{} notation is from unified EL. This is only supported in JSTL 1.2. Your JSTL namespace URI in combination with the fact that you're using JSF indicates that you're actually using JSTL 1.1.

You have 2 options:

  1. Use ${} notation instead. You should only guarantee that the bean is already present in the scope. The ${} notation namely won't auto-create managed beans (the #{} does that).

  2. Upgrade to JSTL 1.2. Download links and details can be found in our JSTL wiki page. Don't forget to change the XML namespace URI to http://java.sun.com/jsp/jstl/core.

Needless to say that option 2 is preferred. You should ban ${} from your JSF pages.

See also:


As a completely different alternative, you could also just use Facelets' own <ui:repeat> instead of the <c:forEach>. You should however understand the major difference that the Facelets one runs during view render time and that the JSTL one runs during view build time. See also JSTL in JSF2 Facelets... makes sense?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I tried using and it finally worked! Thank you very much for your help, I will read all the links you posted. – Saulius Šimčikas Nov 02 '12 at 14:45
  • You're welcome. If I were you, I'd definitely upgrade to JSTL 1.2. Just to prevent problems in the future caused by using an incompatible JSTL version. – BalusC Nov 02 '12 at 14:49
  • Don't underestimate the ignorance about JSTL+JSF. I've even seen senior/lead architects/experts who have it wrong. The two last links posted in my answer should enlighten a lot for them. – BalusC Nov 02 '12 at 16:05
  • @BalusC: Bauke, by mistake you typed `d` instead of `r` in http://java.sun.com/jsp/jstl/code. – Farhan stands with Palestine Mar 16 '16 at 13:42