1

I am upgrading my application from JSF 1.2 to JSF 2.

I am trying a below simple forEach tag but it not showing anything inside the loop.

<table 
    id="tab${sectionId}"
    border="0" 
    cellpadding="0" 
    cellspacing="0" 
    width="100%"
    class="listingTable"
>
    <c:forEach
        var="row" 
        rowStatus="index"
        items="#{bean.department.userActivities}"
    >
        <tr>
            <td>
                test
            </td>
         </tr>
    </c:forEach>
</table>

The value test is not showing up. Has the c:forEach implementaion changed?

I tried replacing with but has some other issue. It is rendering the content inside it. But if I have a component inside , I am not able to assign a backing bean value as ID of the component. Example is as below

<table 
    id="tab${sectionId}"
    border="0" 
    class="listingTable"
>
    <t:dataList
        var="row" 
        rowIndexVar="index"
        value="#{bean.department.userActivities}"
    >
        <h:column>
            <h:outputText id="#{row.activityCode}">test1</h:outputText>
        </h:column>
    </t:dataList>
</table>

So, with . I am not able to assign backing bean property as ID of the component. I am receiving the error "java.lang.IllegalArgumentException: component identifier must not be a zero-length String "

Can anyone please help me in understanding as to why the c:forEach tag is not working. I have huge code which is using forEach tag. With upgrade, I will have to remove every forEach if it is no more supported in JSF2 :(

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1661892
  • 103
  • 4
  • 13

1 Answers1

2

JSTL taglib/XML namespace URI has changed forth and back across JSTL/JSF/Facelets versions.

For JSF on JSP with JSTL 1.0, it is

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>

For JSF on JSP with JSTL 1.1+, it is

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

For JSF 1.x on Facelets with JSTL 1.1+, it is

<xxx xmlns:c="http://java.sun.com/jstl/core">

For JSF 2.x on Facelets with JSTL 1.2+, it is

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

For JSF 2.2+ on Facelets with JSTL 1.2+, it is

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

Make sure you pick the right one.

See also:


Unrelated to the concrete problem, as to the underlying functional requirement which you're actually ultimately trying to solve, head to the following related questions for a thought:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC! I was initially using wrong namespace. I am using 2.2 version and hence changed the namespace as per you reply. However, I ran into another issue- The values of the components inside c:forEach are not bound to backingbean anymore. Is there anything else I am missing? – user1661892 Jul 03 '15 at 18:57
  • You're welcome. Just press Ask Question button if you have a new question. – BalusC Jul 03 '15 at 20:50