views:

675

answers:

1

Hey,

Seems like this should be possible but ...?

Using richfaces and JSF I'm iterating over a List using rich:dataList ... all is fine except I'd like the ability to selectively 'render' each iteration, is that possible?

For example:

<rich:dataList value="#{list}" var="item">
   <h:outputText value="#{item.something}" />
</rich:dataList>

I'd like to be able to render the output selectively, for example if some property of 'item' is true or whatever.

I've tried wrapping the outputText in an outputPanel and similar but if the output panel is not rendered the '<li>' of the iteration is still rendered so you get a bullet point with nothing beside it rather than it just skipping the item entirely :(

Any way of solving this or am I SOL? I realize normally I'd want to get the List of items to display ready before hand but for many reasons I won't bother to repeat here it isn't possible.

+1  A: 

Odd behaviour. I tried to reproduce it with Tomahawk's t:dataList and I am seeing exactly the same behaviour! Best what you can do is to replace it by a4j:repeat and render plain HTML <li> elements manually. Something like:

<ul class="rich-datalist">
    <a4j:repeat value="#{list}" var="item">
        <h:panelGroup rendered="#{item.somecondition}">
            <li class="rich-list-item">
                <h:outputText value="#{item.something}" />
            </li>
        </h:panelGroup>
    </a4j:repeat>
</ul>

(I've borrowed same classnames from rich:dataList as described here so that it keeps the skin)

I personally would however mark it as a bug or at least as undesireable behaviour and report it to the boys behind the component library in question. I've already done it for Tomahawk.

BalusC
I thought of that but is it valid to wrap the 'li' with a panel group? I thought it would result in HTML like:<ul> <span> <li> stuff </li> </span> </ul>which seems bad
hmmm nope doesn't seem to result in spans surrounding the li's, thanks balusc helpful as always :)
You're welcome. It will only render `<span>` when it *needs* to render some **attributes**, e.g. `id`, `style`, `styleClass`, etc.
BalusC
ahh thats good to know and makes sense, thanks again