Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Don't manually create components if everything can just be done in the view. This construct will fail if the bean is in a broader scope than the request scope. See also e.g. <a href="https://stackoverflow.com/questions/2101755/im-getting-duplicate-id-error-after-adding-binding-attribute/2101768#2101768">Binding attribute causes duplicate component ID found in the view</a></p> <p>Follow the showcase example "<a href="http://www.primefaces.org/showcase/ui/tabviewModel.jsf" rel="nofollow noreferrer">TabView with Model</a>" which allows you to dynamically populate tabs via a sane model and <code>&lt;p:tabView value="..." var="..."&gt;</code> like as <code>&lt;ui:repeat&gt;</code>/<code>&lt;h:dataTable&gt;</code>.</p> <p>E.g. this view</p> <pre class="lang-html prettyprint-override"><code>&lt;h:form&gt; &lt;p:tabView value="#{bean.tabs}" var="tab"&gt; &lt;p:tab title="#{tab.title}"&gt; #{tab.content} &lt;p:commandButton value="Close" action="#{bean.remove(tab)}" update="@form" /&gt; &lt;/p:tab&gt; &lt;/p:tabView&gt; &lt;p:commandButton value="Add Tab" action="#{bean.add}" update="@form" /&gt; &lt;/h:form&gt; </code></pre> <p>with this controller</p> <pre><code>@ManagedBean @ViewScoped public class Bean implements Serializable { private List&lt;Tab&gt; tabs; @PostConstruct public void init() { tabs = new ArrayList&lt;&gt;(); } public void add() { tabs.add(new Tab("tab" + tabs.size(), "some content")); } public void remove(Tab tab) { tabs.remove(tab); } public List&lt;Tab&gt; getTabs() { return tabs; } } </code></pre> <p>and this model</p> <pre><code>public class Tab { private String title; private String content; public Tab(String title, String content) { this.title = title; this.content = content; } public String getTitle() { return title; } public String getContent() { return content; } } </code></pre>
 

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