Igor
Igor

Reputation: 1511

Using JSTL with JSF 1.1

I'm trying to use JSTL with JSF 1.1. The following code is causing me a problem:

<c:forEach var="key" items="${names}">
    <h:column>
        <f:facet name="header">
            <h:outputText value="#{key}"/>
        </f:facet>
        <h:outputText value="#{key}"/>
    </h:column>
</c:forEach>

where names is a String list. Names are the key of a map contained in data displayed in the table i.e. I'm trying to do accomplish something like this:

<h:outputText value="#{data.fooMap[key]}"/>

This code is working fine outside h:dataTable (iteration and display of names), but when I put it inside the table nothing is displayed.

Does anyone has a clue how to fix this problem?
Is there a JSF tag that can iterate over the list inside the h:dataTable?

Any help would be appreciated!

Upvotes: 2

Views: 997

Answers (1)

BalusC
BalusC

Reputation: 1109715

JSF and JSTL doesn't run in sync as you'd expect from the coding. During view build time it's JSTL which runs from top to bottom first, the result is a pure JSF component tree without any JSTL tags. Then, during view render time it's JSF which runs from top to bottom again to produce HTML.

If the ${names} is definied as var of the <h:dataTable> then it is simply not available when JSTL is doing its job.

You need to head to a different solution (populating dynamically in backing bean), or to adopt a 3rd party component library which allows generating dynamic columns. For example RichFaces has a rich:columns component which is designed for exactly this purpose.

Upvotes: 5

Related Questions