Search code examples
ajaxprimefacescommandbutton

commandButton update attribute not working


I have a commandButton which opens a dialog containing a table.

When the button is clicked the dialog pops out but it does not contain anything.

This is my code:

<h:panelGroup id="correctionsEntries" layout="block">

    <p:dataTable styleClass="dataTable" id="entriesTable" var="entry" value="#{bean.tableModel.items}">

        <p:columnGroup type="header">
            <p:row>
                <ui:repeat var="column" value="#{bean.tableModel.columns}" varStatus="colStatus">
                    <p:column  headerText="#{column.header}">
                    </p:column>
                </ui:repeat>
            </p:row>
        </p:columnGroup>

        <c:forEach var="column" items="#{bean.tableModel.columns}">

            <c:choose>  
                <c:when test="${column.header eq 'Upload'}">
                    <p:column>
                        <p:commandButton value="Upload" immediate="true" actionListener="#{bean.setSelectedRow(entry)}" oncomplete="PF('upload').show();" />

                        <p:dialog header="Upload" widgetVar="upload" height="10%" width="80%">
                            <p:messages binding="#{bean.component}" /> 
                            <p:fileUpload fileUploadListener="#{bean.uploadCSV}" />
                        </p:dialog>
                    </p:column>
                </c:when>

                <c:when test="${column.header eq 'Export'}">
                    <p:column>
                        <p:commandButton value="Download" immediate="true" ajax="false" actionListener="#{bean.setSelectedRow(entry)}">
                            <p:fileDownload value="#{bean.downloadCSV()}" />
                        </p:commandButton>
                    </p:column>
                </c:when>

                <c:when test="${column.header eq 'Display'}">
                    <p:column>
                        <p:commandButton id="displayButton" value="Display"
                            immediate="true"
                            action="#{tableBean.execute(entry)}"
                            update="displayTable"
                            oncomplete="PF('dialog').show();" />

                        <p:dialog id="dialog" header="Current data" widgetVar="dialog" height="80%" width="80%">

                            <p:dataTable styleClass="dataTable"
                                id="displayTable" var="tableDataVar"
                                value="#{tableBean.tableModel.data}"
                                tableStyle="width:auto;" resizableColumns="true">

                                <p:columns var="tableHeader" value="#{tableBean.tableModel.headers}">
                                    <f:facet name="header">
                                        <h:outputText value="#{tableHeader}" />
                                    </f:facet>
                                    <h:outputText value="#{tableDataVar[tableHeader]}" />

                                </p:columns>

                            </p:dataTable>

                        </p:dialog>
                    </p:column>
                </c:when>

                <c:when test="${column.header eq 'Test'}">
                    <p:column>
                        <p:commandButton value="Test" immediate="true" ajax="false" actionListener="#{bean.setSelectedRow(entry)}">
                            <p:fileDownload value="#{bean.testFilesDownload()}" />
                        </p:commandButton>
                    </p:column>
                </c:when>

                <c:otherwise>
                    <p:column>
                        <h:outputText value="#{bean.tableModel.get(entry, column)}" />
                    </p:column>
                </c:otherwise>
            </c:choose>
        </c:forEach>

    </p:dataTable>  

</h:panelGroup>

The table is displayed only after refreshing the page.


Solution

  • The problem is that a dialog containing the table is created for each of the column from the parent table.

    Therefore there are as many dialog as there are columns.

    The fix for this was adding the dialog in a separate form, and referring it in the commandButton by specifying its path.