confirmDialog 未呈现

confirmDialog is not rendered

我目前正在学习 JavaEE7 教程,当前章节是 JSF/PrimeFaces。我需要为删除操作添加一个确认对话框,页面呈现正常。当我按下 commandButton(第 14 行)时,actionListener 触发,但 confirmation.show() 在 Web 控制台中产生错误:"Reference error: confirmation is not defined" 并且 confirmDialog 不会呈现。据我了解,"widgetVar=confirmation" 是定义。想知道我做错了什么。

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui">   
<body>
    <f:view contracts="#{view.locale.language}">
        <ui:composition template="/template.xhtml">
            <ui:define name ="content">
                <h1>#{msg['listCampaigns.my_campaigns']}</h1>
                <h:form>
                    <p:dataTable value="#{campaignListProducer.campaigns}" var="campaign">
                        <p:column>
                            <p:commandButton onclick="confirmation.show()" actionListener="#{listCampaignsController.doDeleteCampaign(campaign)}" icon="ui-icon-close" />
                        </p:column>
                        <p:column>
                            <f:facet name="header">#{msg['listCampaigns.name']}</f:facet>
                            <h:outputText value="#{campaign.name}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header">#{msg['listCampaigns.target_amount']}</f:facet>
                            <h:outputText value="#{campaign.targetAmount}">
                                <f:convertNumber type="currency" currencyCode="EUR" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">#{msg['listCampaigns.donated_so_far']}</f:facet>
                            <h:outputText value="#{campaign.amountdonatedSoFar}">
                                <f:convertNumber type="currency" currencyCode="EUR" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <p:commandLink value="#{msg['listCampaigns.edit']}" ajax="false" action="#{listCampaignsController.doEditCampaign(campaign)}">
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink value="#{msg['listCampaigns.list_donations']}" ajax="false" action="#{listCampaignsController.doListDonations(campaign)}">
                            </p:commandLink>
                        </p:column>
                        <p:column>
                            <p:commandLink value="#{msg['listCampaigns.form']}" ajax="false" action="#{listCampaignsController.doEditDonationForm(campaign)}">
                            </p:commandLink>
                        </p:column>                                                           
                    </p:dataTable>
                    <p:commandButton value="#{msg['listCampaigns.add_campaign']}" ajax="false" action="#{listCampaignsController.doAddCampaign()}" />                            
                    <p:confirmDialog message="#{msg['listCampaigns.ask_delete_campaign']}" 
                                     header="#{msg['listCampaigns.delete_campaign']}" 
                                     severity="alert" 
                                     widgetVar="confirmation" >
                        <p:commandButton value="#{msg['listCampaigns.yes']}" 
                                         oncomplete="confirmation.hide()" 
                                         ajax="false" 
                                         actionListener="#{listCampaignsController.commitDeleteCampaign}" />
                        <p:commandButton value="#{msg['listCampaigns.no']}" onclick="confirmation.hide()" type="button" />
                    </p:confirmDialog>                        
                </h:form>
        </ui:define>
    </ui:composition>
</f:view>

您需要像这样访问您的对话框 PF('confirmation') 例如PF('confirmation').show()

这是版本 5 版本中引入的更改

Widgets must be referenced via "PF". e.g. PF('widgetVarName').show() instead of widgetVarName.show();

https://code.google.com/p/primefaces/wiki/MigrationGuide