繁体   English   中英

p:dialog中的p:commandButton不调用actionListener方法

[英]p:commandButton in p:dialog does not call actionListener method

我有以下页面,以某种方式

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

不调用actionListener中指定的方法。 我检查了这篇文章中的所有选项,一切似乎都是正确的。 我想念什么吗?

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>

在对话框中,您将内容放置在新表单中

<h:form id="editPanel">

您可以删除此表单并重新运行代码吗?

因此,现在您的所有内容都应在您要在此行创建的一种表单内:

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

您可以显示dataBean.update的声明吗?

通常,动作侦听器方法应返回void并将ActionEvent作为参数。

您是否尝试使用action代替actionListener?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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