Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF Component IDs ignored when dynamically generating Views
    text
    copied!<p>I ran into a bit of a problem. </p> <p>I generate Views dynamically by iterating a list of strings via the c:forEach tag and then including them via the facelets include tag. </p> <p>This works fine for building the layout but shows some strange behaviour. </p> <p>I have a primefaces tabview containing 2 tabs. For the first Tab (the one that gets initially displayed) the component id is set (eg. tabview:categoryTab) but that's not the case for e.g. the second tab, here I only get tabview: for the component id (but it actually should be tabview:usrTab)</p> <p>Why does JSF override the id I set for the second Tab? Am I missing some crucial information from the spec? </p> <p>I use JSF 2 with Primefaces 3.6 (snapshot build) (And yes, I use the snapshot build on purpose and have tested this with stable PF releases as well but the same behaviour occurs)</p> <hr> <p>edit</p> <p>Code: admin.xhtml</p> <pre><code>&lt;ui:composition template="/templates/commonLayout.xhtml"&gt; &lt;ui:define name="content"&gt; &lt;p:panel id="parentPanel"&gt; &lt;h:outputText value="Verwaltung" /&gt; &lt;br /&gt; &lt;p:tabView id="tabview"&gt; &lt;!-- insert marker --&gt; &lt;c:forEach items="#{adminTabs}" var="tab"&gt; &lt;ui:include src="#{tab}" /&gt; &lt;/c:forEach&gt; &lt;/p:tabView&gt; &lt;/p:panel&gt; &lt;/ui:define&gt; &lt;/ui:composition&gt; </code></pre> <p>catTab.xhtml</p> <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;p:tab title="Categories Tab" id="catTab"&gt; .... &lt;/p:tab&gt; &lt;/ui:composition&gt; </code></pre> <p>usrTab.xhtml</p> <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;p:tab title="Users Tab" id="usrTab"&gt; .... &lt;/p:tab&gt; &lt;/ui:composition&gt; </code></pre> <p>testTab.xhtml</p> <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets"&gt; &lt;p:tab title="TestTab" id="testTab"&gt; .... &lt;/p:tab&gt; &lt;/ui:composition&gt; </code></pre> <p>ContentProvider.java</p> <pre><code> public class ContentProvider { .... @Produces @Named("adminTabs") public List&lt;String&gt; getTabs(){ List&lt;String&gt; components = new ArrayList&lt;String&gt;(); components.add("/templates/tabs/catTab.xhtml"); components.add("/templates/tabs/usrTab.xhtml"); components.add("/templates/tabs/testTab.xhtml"); return components; } .... } </code></pre> <p>This gets generated:</p> <pre><code>&lt;ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist"&gt; &lt;li class="ui-state-default ui-tabs-selected ui-state-active ui-corner-top" aria-expanded="true" role="tab"&gt; &lt;a href="#tabview:catTab"&gt;Categories&lt;/a&gt; &lt;/li&gt; &lt;li class="ui-state-default ui-corner-top" aria-expanded="false" role="tab"&gt; &lt;a href="#tabview:j_idt31"&gt;TestTab&lt;/a&gt; &lt;/li&gt; &lt;li class="ui-state-default ui-corner-top" aria-expanded="false" role="tab"&gt; &lt;a href="#tabview:j_idt32"&gt;Benutzer und Rollen&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>So, to reiterate: Only the id for the first tab is retained, the ids for the other tabs are generated despite being set in the xhtml code... </p>
 

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