简体   繁体   中英

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

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.

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.

why not use jstl

<c:forEach var="person" items="${people.people}">
        <tr>
          <td>${person.name}</td>
          <td>${person.age}</td>
          <td>${person.height}</td>
        </tr>
      </c:forEach>

or

<ui:repeat value="#{TableBean.perInfoAll}" var="info">
   <li> 
  <h:inputText value="#{info.id}" />
  <h:inputText value="#{info.name}" />
   </li> 
  </ui:repeat>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM