Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use an iterating component like <code>&lt;h:dataTable&gt;</code> or <code>&lt;ui:repeat&gt;</code> to display a dynamically sized <code>List</code> of entities. Make the bean <code>@ViewScoped</code> to ensure that the list is remembered across postbacks on the same view instead of recreated over and over.</p> <p>Kickoff example with <code>&lt;h:dataTable&gt;</code>:</p> <pre><code>&lt;h:form&gt; &lt;h:dataTable value="#{bean.items}" var="item"&gt; &lt;h:column&gt;&lt;h:inputText value="#{item.value}" /&gt;&lt;/h:column&gt; &lt;h:column&gt;&lt;h:commandButton value="remove" action="#{bean.remove(item)}" /&gt;&lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;h:commandButton value="add" action="#{bean.add}" /&gt; &lt;h:commandButton value="save" action="#{bean.save}" /&gt; &lt;/h:form&gt; </code></pre> <p>Managed bean:</p> <pre><code>@ManagedBean @ViewScoped public class Bean { private List&lt;Item&gt; items; @PostConstruct public void init() { items = new ArrayList&lt;Item&gt;(); } public void add() { items.add(new Item()); } public void remove(Item item) { items.remove(item); } public void save() { System.out.println("items: " + items); } public List&lt;Item&gt; getItems() { return items; } } </code></pre> <p>Model:</p> <pre><code>public class Item { private String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } public String toString() { return String.format("Item[value=%s]", value); } } </code></pre> <h3>See also:</h3> <ul> <li><a href="https://stackoverflow.com/questions/3180400">Recommended JSF 2.0 CRUD frameworks</a></li> <li><a href="https://stackoverflow.com/questions/3510614">How to create dynamic JSF form fields</a></li> <li><a href="https://stackoverflow.com/questions/6358066">How to implement a dynamic list with a JSF 2.0 Composite Component?</a></li> <li><a href="https://stackoverflow.com/questions/7031885">How to choose the right bean scope?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload