1

I got a primefaces treeTable and use additionally c:forEach to create dynamic columns. Is there a way to identify those columns inside the c:forEach from another form? (If I set an id for my columns inside the c:forEach, I get an duplicated ID error)

<h:form id="mmvUebersicht">
<p:treeTable id="massnahmenUebersichtTable"
            value="#{mmvOrganisationseinheitenTreeHandler.root}"
            var="_tree"
            selection="#{mmvOrganisationseinheitenTreeHandler.selectedNode}"
            selectionMode="single"
            scrollable="true"
            scrollHeight="500">

            <p:ajax event="expand" listener="#{mmvOrganisationseinheitenTreeHandler.onNodeExpand}" />
            <ui:remove>
            <p:ajax event="select" update=":mmvUebersichtEastForm" listener="#{mmvOrganisationseinheitenTreeHandler.onNodeSelect}" />
            </ui:remove>

        <p:column headerText="#{labels.abteilung}" style="width:250px">
            <p:outputLabel value="#{_tree.id} #{_tree.shortNameName}"/>
        </p:column>

        <p:column headerText="#{labels.funktion}" style="width:150px">
            <p:outputLabel value="#{structureNodeHandler.getAttributeCommentByAttributeType(_tree, 'Leitung')}" />
        </p:column>
        <p:column headerText="#{labels.verantwortlich}" style="width:150px">
            <p:outputLabel value="#{mmvHelper.getUserByRacf(structureNodeHandler.getAttributeValueByAttributeType(_tree, 'Leitung'))}"/>            
        </p:column>

        <c:forEach items="#{massnahmenDefintionListHandler.defList}"
                    var="_mass"
                    >
            <p:column style="width:50px">
            <f:facet name="header">
                <p:outputLabel value="#{_mass.kurzName}" title="#{mass.name}"/>
            </f:facet>    

              <p:commandLink onclick="mmvlayout.show('east')"
                            update=":mmvContentPanelEast :mmvUebersichtEastForm" 
                            action="#{mmvHandler.fillUebersichtEastPanel(_tree,_mass)}"
                            rendered="#{massnahmenErfuellungsObjekt.abteilungHasMassnahme(_tree,_mass,true)}">
                <h:outputText value="#{massnahmenErfuellungsObjekt.bestimmeMassnahmenFaelligkeiten(_tree,_mass,true)}" 
                            styleClass="#{massnahmenErfuellungsObjekt.cellColor()} statusBar"/>
              </p:commandLink>


            </p:column>

        </c:forEach>

        <p:column style="width:*"></p:column>

</p:treeTable>

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
LStrike
  • 1,598
  • 4
  • 26
  • 58

1 Answers1

2

If I set an id for my columns inside the c:forEach, I get an duplicated ID error\

It's because the <c:forEach> generates physically multiple JSF components in the JSF component tree instead of only one which is in turn reused multiple times during generating HTML output. See for an elaborate explanation of the working also JSTL in JSF2 Facelets... makes sense?

In such case you're responsible yourself for setting an unique ID on those JSF components. You can use the current iteration index for that.

<c:forEach ... varStatus="loop">
    <p:commandLink id="link_#{loop.index}" ...>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC. The interesting thing is, how to get the loop.index inside a different form and send an update request to that column with this loop index? – LStrike Sep 09 '13 at 12:35
  • 1
    The JSTL loop index is in this case not the problem, it should work perfectly fine as this is present in both JSF component tree (`UIViewRoot#findComponent()` is able to return the right thing) as well as in HTML DOM tree (`document.getElementById()` is able to find the right thing on exactly that client ID). However, the problem is in this case the ``'s own index (the `:0`, `:1`, etc prefix). This is not present in JSF component tree. So you still have got to update the whole `` thing (or to replace it by another ``... :X ) – BalusC Sep 09 '13 at 12:46
  • Hmm, I think I understand what you mean. If I have to update the whole treeTable, I would have to cache or store which nodes where expanded and which not. I think this is a lot of work for me ;-) – LStrike Sep 09 '13 at 14:35
  • Problem solved ;-). I just added a list of TreeNodes to my TreeHandler bean in which I store those Nodes which where expanded. During updating the whole tree I just check the list, if it contains my Node, if true I set expanded = true, else not. – LStrike Sep 10 '13 at 08:16