2
votes

The following code loops thru a list from a database and builds a data table for each entry. Each entry has a List of columns that will be displayed in the data table. The problem I am having is that the value attribute of the p:columns, in the composite code, is not being changed when the composite is called a second time. It seems to cache the initial list of columns. Is there a way to reset the columns tag so that it uses the new columns list.

UPDATE It seems that the second data table is using the previous data tables row value name for the first row of the first cell. Everything else is fine. Here is a screen shot

2nd UPDATE I have also noticed that if you go to the second page of the second datatable and then back to the first page the broken cell, circled in the image, fixes it's self with the correct value.

3rd UPDATE In my code below I am using a ui:repeat tag. I have also used the primeface:accordian tag and they both produce the problem. I changed the ui:repeat tag with a c:forEach tag and that fixed the problem in the image below. The issue I still have is That I need this to be in a primefaces accordian tag so that I can dynamically build a tab for each data table. I thought my issues was in the p:columns tag of the data table, but it now seems to be in the ui:reat or p:accordian tags which both use the value="#{myBeanList}" attribute

enter image description here

 <ui:repeat var="codetable" value="#{pc_Maintenence.codeMaintenenceTables}">
        <util:maintenence_code pageBean="#{pc_Maintenence}" dataTableInfo="#{codetable}"
                paginator="true" rows="10"/>
    </ui:repeat>

This is the composite code that is called in the above code util:maintenence_code.

    <composite:interface>
        <composite:attribute name="pageBean" required="true" />
        <composite:attribute name="dataTableInfo" required="true" />
        <composite:attribute name="paginator" type="java.lang.Boolean" />
        <composite:attribute name="rows" />
    </composite:interface>

    <composite:implementation>

        <p:panel id="pnl_doc_code_table">
           <p:dataTable value=#{cc.attrs.pageBean.getDataTableList(cc.attrs.dataTableInfo.tableListName)}"
                var="tblVar" paginator="#{cc.attrs.paginator}"
                rows="#{cc.attrs.rows}" dynamic="true" cache="false">

                 <p:columns var="column" styleClass="columns" id="columns" value="#{cc.attrs.dataTableInfo.columns}">

                       #{tblVar[column.name]}

                  </p:columns>
              </p:dataTable>
           </p:panel>
   </composite:implementation>
1
And Java inherited its syntax mostly from C. Let me add C tag then... By the way, F stands for Faces.skuntsel
As stated in the 2nd update using pagination the first cell of the first row gets the correct value. Why does pagination's ajax call fix the problem and a page refresh will put the wrong value in. I also did some testing where I added more than two data tables and the wrong value is always in the first row first cell and always from the datatable just above the current data table.Doug
it's just a suggestion try put them in a form then update the datatable when the event is executedFarnsbert
The above code was already in a form tag. Sorry that I did not include that. Also I tried to refresh the table after it was built and that did not seem to fix the problem.Doug

1 Answers

0
votes

I have solved the problem. The issue seems to be when you create dynamic primefaces:datatables that use the primefaces:columns tag. When the data tables are created within a ui:repeat tag or using the primefaces:accordianPanel's looping ability, then every data table created after the first has a wrong value in the first cell of the first row. All other cells in the data table have the correct values. I have also noticed that the headerText is wrong and always from the previous data tables headerText (The first data table's headerText is always right).

To solve this issue I placed the jstl:forEach tag inside of the primefaces:accordianPanel tag. This fixed the issue. It seems to be an issue with how the ui:repeat and/or the primefaces:accordianPanel is rendering the data tables. Here is the code that is working correctly.

<h:form styleClass="form" id="frmcodes">
        <p:tabView styleClass="tabView" id="tabview_maintenence" rendered="#{user.khecorpAdmin}">
            <p:tab id="tab_code_tables" title="Code Tables">
                <p:accordionPanel id="pnl_accord_codetables">
                   <c:forEach items="#{pc_Maintenence.codeMaintenenceTables}" var="codetable">
                       <p:tab title="#{codetable.tableName}">                   
                           <util:maintenence_code pageBean="#{pc_Maintenence}" dataTableTemplate="#{codetable}"/>
                       </p:tab>
                    </c:forEach>
                </p:accordionPanel>
             </p:tab>
          </p:tabView>
          <p:messages id="msg" autoUpdate="true"/>
    </h:form>

Here is the composite code that builds the data tables

<composite:interface>
        <composite:attribute name="pageBean" required="true"/>
        <composite:attribute name="dataTableTemplate" required="true" />
    </composite:interface>

    <composite:implementation>
        <p:panel id="pnl_table">

            <p:dataTable value="#{cc.attrs.pageBean.getDataTableList(cc.attrs.dataTableTemplate.tableListName)}"
                var="tblVar" paginator="true" rows="10" rowIndexVar="tblIndx"
                editable="#{cc.attrs.dataTableTemplate.editable}">

                <p:columns id="columns" value="#{cc.attrs.dataTableTemplate.columns}" 
                    var="column" headerText="#{column.heading}">

                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{tblVar[column.name]}"/>
                        </f:facet>

                        <f:facet name="input" rendered="#{column.editable}">
                            <p:inputText value="#{tblVar[column.name]}" rendered="#{column.editable}"/>
                        </f:facet>
                    </p:cellEditor>
                </p:columns>
                <p:column rendered="#{cc.attrs.dataTableTemplate.editable}">  
                    <p:rowEditor /> 
                </p:column>
            </p:dataTable>
        </p:panel>
    </composite:implementation>