How to iterate over an arraylist in jsf without `<t:datatable>` or `<t:datalist>`

Abhishek Dhote picture Abhishek Dhote · Dec 10, 2011 · Viewed 10.8k times · Source

How to get the following result in JSF with

<div id="tagcloud">
    <a href="#" rel="0.1">Lorem</a>
    <a href="#" rel="2">ipsum</a>
    <a href="#" rel="3">dolor</a>
    <a href="#" rel="4">sit</a>
    <a href="#" rel="5">amet,</a>
    <a href="#" rel="6">consectetur</a>
    <a href="#" rel="7">adipisicing</a>
</div>

I tried <t:datatable> or <t:datalist> but both are not able to.

Answer

Arjan Tijms picture Arjan Tijms · Dec 10, 2011

Assuming you use Facelets, the following should do it:

<div id="tagcloud">
    <t:dataList value="#{backingBean.items}" var="item" layout="simple">
        <a href="#" rel="#{item.rel}">#{item.name}</a>
    </t:dataList>
</div>

If you're using JSP (hope not), you can replace #{item.name} with an h:outputText.

backingBean.items in the example points to some backing bean that returns a List with the values that differ for each row.