简体   繁体   中英

p:commandButton in p:dialog does not call actionListener method

I have the following page and somehow the

<p:commandButton value="Save" update="data" oncomplete="edit.hide();" actionListener="#{dataBean.update}" />

does not call the method speficied in the actionListener. I checked all the options from this post and everything seems to be correct. Am I missing something?

Page

<h:body id="body" style="margin:50px; font-size: 80%">
<f:view contentType="text/html">
    <h:form>
        <p:ajaxStatus onstart="statusDialog.show();"
            onsuccess="statusDialog.hide();" />

        <p:dialog modal="true" widgetVar="statusDialog" header="Processing"
            draggable="false" closable="false" resizable="false" width="255">
            <p:graphicImage value="./images/ajax-loader.gif" />
        </p:dialog>

        <p:commandButton value="Delete selected"
            onclick="confirmationSelected.show()" />

        <p:commandButton value="Refresh data" update="data"
            style="float:right" actionListener="#{dataBean.refresh}" />

        <p:dataTable var="item" value="#{dataBean.records}" id="data"
            paginator="true" rows="10" selection="#{dataBean.selectedRecords}"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15,20,25,50,100">

            <f:facet name="header">Stored records</f:facet>

            <p:column selectionMode="multiple" />
            <p:column style="width:18px; text-align:center;">
                <p:rowToggler />
            </p:column>
            <p:column headerText="Time" style="width:80px; text-align:center;"
                sortBy="#{item.time}" filterby="#{item.time}"
                filterMatchMode="contains">
                <h:outputText value="#{item.time}">
                    <f:convertDateTime type="both" dateStyle="short" />
                </h:outputText>
            </p:column>
            <p:column headerText="URL" style="word-break: break-all"
                sortBy="#{item.url}" filterby="#{item.url}"
                filterMatchMode="contains">
                <h:outputText value="#{item.url}" />
            </p:column>
            <p:column headerText="Rating" style="width:80px; text-align:center;"
                sortBy="#{item.rating}" filterby="#{item.rating}"
                filterMatchMode="contains">
                <h:outputText value="#{item.rating}" />
            </p:column>
            <p:column headerText="Key" style="width:80px; text-align:center;"
                sortBy="#{item.key}" filterby="#{item.key}"
                filterMatchMode="contains">
                <h:outputText value="#{item.key}" />
            </p:column>
            <p:column headerText="Actions"
                style="text-align:center; width:100px;">
                <p:commandLink value="Edit" oncomplete="edit.show()"
                    update="editPanel">
                    <f:setPropertyActionListener target="#{dataBean.key}"
                        value="#{item.key}" />
                </p:commandLink>
                &nbsp;
                <p:commandLink value="Delete" onclick="confirmation.show()">
                    <f:setPropertyActionListener target="#{dataBean.key}"
                        value="#{item.key}" />
                </p:commandLink>
            </p:column>
            <p:rowExpansion>
                <p:tabView>
                    <p:tab title="Page source">
                        <div
                            style="max-height: 300px; overflow-y: auto; word-break: break-all">#{item.page}</div>
                    </p:tab>

                    <p:tab title="Snippet">
                        <div
                            style="max-height: 300px; overflow-y: auto; word-break: break-all">#{item.snippet}</div>
                    </p:tab>
                </p:tabView>
            </p:rowExpansion>
        </p:dataTable>

        <p:confirmDialog message="Are you sure you want to delete this item?"
            header="Delete" severity="alert" widgetVar="confirmation"
            modal="true">
            <p:commandButton value="OK" oncomplete="confirmation.hide()"
                actionListener="#{dataBean.deleteOne}" update="data" />
            <p:commandLink value="Cancel" onclick="confirmation.hide()" />
        </p:confirmDialog>

        <p:confirmDialog
            message="Are you sure you want to delete all selected items?"
            header="Delete" severity="alert" widgetVar="confirmationSelected"
            modal="true">
            <p:commandButton value="Delete"
                oncomplete="confirmationSelected.hide()"
                actionListener="#{dataBean.deleteSelected}" update="data" />
            <p:commandLink value="Cancel" onclick="confirmationSelected.hide()" />
        </p:confirmDialog>

    </h:form>
    <p:dialog header="Edit record" widgetVar="edit" resizable="true"
        width="850" height="500" modal="true">
        <h:form id="editPanel">
            <h:outputText value="Record ID = #{dataBean.selectedRecordKey}"
                style="font-size:12pt;" />
            <p:separator />
            <h:panelGrid columns="6">
                <h:outputText style="margin-left:-2px;" value="Time:" />
                <h:inputText value="#{dataBean.selectedRecordTime}"
                    style="width: 230px" />

                <h:outputText style="margin-left:20px;" value="Url:" />
                <h:inputText value="#{dataBean.selectedRecordUrl}"
                    style="width: 375px" />

                <h:outputText style="margin-left:20px;" value="Rating:" />
                <p:spinner value="#{dataBean.selectedRecordRating}" min="1" max="5"
                    style="width: 30px" width="20" showOn="never" />
            </h:panelGrid>
            <br />
            <p:tabView>
                <p:tab title="Page source">
                    <h:inputTextarea value="#{dataBean.selectedRecordPage}" rows="13" cols="108" />
                </p:tab>

                <p:tab title="Snippet">
                    <h:inputTextarea value="#{dataBean.selectedRecordSnippet}" rows="13" cols="108" />
                </p:tab>
            </p:tabView>
            <br />
            <p:commandButton value="Save" update="data"
                oncomplete="edit.hide();" actionListener="#{dataBean.update}" />
            <p:commandLink value="Cancel" onclick="edit.hide()"
                style="margin-left:10px;" />
        </h:form>
    </p:dialog>
</f:view>

Inside your dialog you are placing your contents inside a new Form

<h:form id="editPanel">

Can you remove this form and rerun your code ?

So now all your content should be inside one form which you are creating at this line :

<f:view contentType="text/html">
<h:form>

Can you show declaration of your dataBean.update ?

Usually action listener method should return void and have ActionEvent as parameter.

Did you try to use action instead of actionListener?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM