Question

I'm trying to manually build an HTML form in JSF, using ui:repeat. Now I have some trouble with the "rendered" attribute. My code is as following:

<ui:repeat varStatus="status" value="#{bean.keys}" var="key">
    <tr jsf:rendered="#{status.index%4==0}">
        <td id="#{key}">
             contents
        </td>
    </tr> <!--or even </tr  jsf:rendered="#{status.index%4==0}">-->
</ui:repeat>

I try to render the <tr> tag conditionally, but I want to render the child element <td> unconditionally, every iteration. I know it is not standard behaviour of JSF, because it will not display children of an unrendered element by default, but is there another way to implement this requirement? I've also tried:

<tr>
    <ui:repeat varStatus="status" value="#{bean.keys}" var="key">
        <td id="#{key}">
             contents
        </td>
        <h:panelgroup rendered="#{status.index%4==0}"></tr><tr></h:panelgroup>
    </ui:repeat>
</tr>

But this last fragment will not parse, because the closing is unexpected (it expects a closing tag for h:panelgroup)

Was it helpful?

Solution

Emit it as escaped HTML.

<h:outputText value="&lt;/tr&gt;&lt;tr&gt;" escape="false" rendered="#{status.index%4==0}" />

The escape="false" is just to avoid that JSF escapes it once more as part of XSS attack prevention which would cause it to end up as &amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top