Reputation: 1319
I am currently going through a tutorial for JavaEE7, current chapter is JSF/PrimeFaces. I need to add a confirmation dialog for a delete action, the page renders fine. When I press the commandButton (line 14) the actionListener fires, but confirmation.show() produces an error in the web console : "Reference error: confirmation is not defined" and the confirmDialog won´t render. As I understand it, "widgetVar=confirmation" is the definition. Would like to know what I´m doing wrong.
<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>
Upvotes: 3
Views: 1631
Reputation: 28519
You need to access your dialog like this PF('confirmation')
e.g. PF('confirmation').show()
Its the change that was introduced with the version 5 release
Widgets must be referenced via "PF". e.g. PF('widgetVarName').show() instead of widgetVarName.show();
https://code.google.com/p/primefaces/wiki/MigrationGuide
Upvotes: 8