4

I have this code that actually works:

<s:iterator value="breadcrumb.links" var="link">
    <s:url action='%{#link.url}' var="url" />
    <li>
       <a href="${url}">${link.name}</a>
    </li>
</s:iterator>

How con I do the same thing but with c:foreach instead of s:iterator ?

I tried with:

<c:forEach items="${breadcrumb.links}" var="link">
    <s:url action='${link.url}' var="url" />
    <li>
        <a href="${url}">${link.name}</a>
    </li>
</c:forEach>

but I get the error:

According to TLD or attribute directive in tag file, attribute action does not accept any expressions

Thankyou.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Simone Conti
  • 544
  • 3
  • 9
  • 20
  • Apart from the question, why do you want to do that ? – Andrea Ligios Dec 08 '13 at 21:11
  • Becouse I don't feel confortable with struts tags s:iterator and OGNL %{#}. I'd like to stick to JSTL c:foreach and EL ${}. Also I always read that EL and OGNL can do the same things, only in different ways. But in this case I cant't find a way with EL. – Simone Conti Dec 09 '13 at 09:00
  • This evening I'll try you code and post the results, thankyou. – Simone Conti Dec 09 '13 at 16:05

1 Answers1

6

To be more comfortable with Struts2 tags and OGNL language, read and bookmark this answer.

Since Struts2 tags only evaluate OGNL expressions (and not EL Expression, as you error clearly states), you need to access the JSTL object through the PageContext attribute (in OGNL #attr.something) specified with var :

<c:forEach items="${breadcrumb.links}" var="link">
    <s:url action='%{#attr.link.url}' var="url" />
    <li>
        <a href="${url}">${link.name}</a>
    </li>
</c:forEach>

From OGNL Basics:

#attr['foo'] or #attr.foo : Access to PageContext if available, otherwise searches request/session/application respectively

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243