PrimeFaces CommandButton does not Update - ajax

I'm trieng to update a gridPanel by pressing a Button(the Pie/Bar chart should not be shown):
<h:form>
<div class="ui-grid ui-grid-responsive">
<div class="ui-grid-row">
<div class="ui-grid-col-4">
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank">
...
<p:panelGrid columns="2" layout="grid" id="buttons"
styleClass="ui-panelgrid-blank">
<p:commandButton update="#form"
actionListener="#{buttonView.pieChart}" icon="ui-icon-disk"
title="Zeige Pie an" />
<p:commandButton update="#form"
actionListener="#{buttonView.barChart}" icon="ui-icon-disk"
title="Zeige Bar an" />
</p:panelGrid>
</p:panelGrid>
</div>
<div class="ui-grid-col-8">
<p>...</p>
<p:panelGrid columns="1" layout="grid"
styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" model="#{userBean.model}"
responsive="true" />
<p:chart id="bar" type="bar" model="#{chartView.barModel}"
style="height:300px" responsive="true" />
</p:panelGrid>
</div>
</div>
</div>
</h:form>
My code somehow does not seem to work.

To hide and show the chart you have to define the rendered attribute rendered. The rendered attribute takes a boolean value.
<p:panelGrid columns="1" layout="grid" styleClass="ui-panelgrid-blank" id="charts">
<p:chart id="pie" type="pie" rendered="#{buttonView.showPieChart}" model="#{userBean.model}" responsive="true" />
<p:chart id="bar" type="bar" rendered="#{buttonView.showBarChart}" model="#{chartView.barModel}" style="height:300px" responsive="true" />
</p:panelGrid>
The value should be set in your Backing Bean for example in buttonView.
public class ButtonView {
...
private boolean isShowPieChart;
private boolean isShowBarChart;
...
}
Finally toggle the boolean values.
<p:commandButton update="#form" actionListener="#{buttonView.pieChart}" icon="ui-icon-disk" title="Zeige Pie an" >
<f:setActionPropertyListener target="#{buttonView.showPieChart}" value="#{!buttonView.showPieChart}" />
</p:commandButton>
<p:commandButton update="#form" actionListener="#{buttonView.barChart}" icon="ui-icon-disk" title="Zeige Bar an" >
<f:setActionPropertyListener target="#{buttonView.showBarChart}" value="#{!buttonView.showBarChart}" />
</p:commandButton>

Related

Page refresh calls the action listener function

I have a JSF application. In the home.xhtml, I have included 4 tabs. Each tab is a different xhtml form. The first form has an action listener. The problem is on all 4 tabs if I refresh (F5) the page, the action listener gets called.
On click of the command button, I check the DB to check if there are existing employees with the same details. If yes, I show the confirm dialog to proceed with Generation. If the user clicks Yes here, the new ID is generated. This generation function gets called again and again if I refresh the page. I made the call as ajax="false" as well but it does not help. If I make ajax="true", It does not let me change the tabs. The page sort of hangs. Please suggest me on how to stop this.
<h:form id="employeeIdGenerationForm" prependId="false">
<p:confirmDialog id="confirmationID" widgetVar="confirmationVar" header="Confirmation" showEffect="fade" hideEffect="explode"
message="#{employeeMaintenanceBean.employee.getWarningsList()}"
rendered="#{employeeMaintenanceBean.showExistingEmployeeWarning}" closable="false">
<p:commandButton value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" onclick="PF('confirmationVar').hide()"
actionListener="#{employeeMaintenanceBean.generateEmployeeID}" ajax="false"
update="#form:confirmation #form:msgPanel_EmployeeIDGeneration #form:firstName #form:surName" />
<p:commandButton value="No" styleClass="ui-confirmdialog-no" icon="ui-icon-close" onclick="PF('confirmationVar').hide()"/>
</p:confirmDialog>
<p:panel styleClass="messagePanel"
style="color: #004986; font-size: 15px;"
header="New Employee ID Generation">
<br />
<h:panelGrid columns="1" id="msgPanel_EmployeeIDGeneration"
width="100%" align="center" style="text-align:center;">
<p:messages />
</h:panelGrid>
<h:panelGrid columns="2" border="0">
<h:outputLabel styleClass="label" value="First Name" />
<p:inputText value="#{employeeMaintenanceBean.employee.firstName}"
id="firstName" required="true"
requiredMessage="First Name is mandatory" maxlength="50"
styleClass="value" />
<h:outputLabel styleClass="label" value="Last Name" />
<p:inputText value="#{employeeMaintenanceBean.employee.lastName}"
id="surName" required="true"
requiredMessage="Last Name is mandatory" maxlength="50"
styleClass="value" />
<h:outputLabel styleClass="label" value="Comments" />
<p:inputTextarea
value="#{employeeMaintenanceBean.employee.comments}" id="comments"
maxlength="256" styleClass="value" />
<p:commandButton id="generateID" ajax="false"
actionListener="#{employeeMaintenanceBean.isExistingEmployee}"
title="Generate Employee ID" value="Generate Employee ID" update="#form:confirmationID #form:msgPanel_EmployeeIDGeneration">
</p:commandButton>
</h:panelGrid>
</p:panel>
</h:form>
The main home.xhtml is:
<h:head/>
<h:body>
<ui:composition template="/template/common/commonLayout.xhtml">
<ui:define name="content">
<p:idleMonitor timeout="300000">
<p:ajax event="idle" listener="#{baseBean.sessionTimeOut}"/>
</p:idleMonitor>
<p:tabView id="tabView" activeIndex="#{tabViewBean.mainTabActiveIndex}" dynamic="true" cache="false">
<p:ajax event="tabChange" listener="#{tabViewBean.onMainTabChange}" update="tabView" />
<p:tab id="employeeIdGeneration" title="New Employee ID Generation" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeIdGeneration')}">
<ui:include src="employeeIdGeneration.xhtml"/>
</p:tab>
<p:tab id="employeeMaintenance" title="Update New Employee Details" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeMaintenance')}">
<ui:include src="employeeIdMaintenance.xhtml"/>
</p:tab>
<p:tab id="employeeHistoryView" title="New Employee Update History" rendered="#{tabViewBean.currentUser.hasAccessToPage('employeeHistoryView')}">
<ui:include src="employeeHistoryView.xhtml"/>
</p:tab>
<p:tab id="userAccessMaintenance" title="User Access Maintenance" rendered="#{tabViewBean.currentUser.hasAccessToPage('userAccessMaintenance')}">
<ui:include src="userMaintenance.xhtml"/>
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</h:body>

How to make required = true in inputtext inside <p:dialog>

So, basically I just want to set inputTextArea validation is not null / required = true, but when I set that, it's effect other button too. So, i should set param and it won't effect other button.
But, it makes the validation isn't working. Here's my code :
<p:dialog id="ajaxdialogs" header="Hapus Data" modal="true" widgetVar="dlg1" showEffect="fade" hideEffect="fade" closable="true">
<p:messages id="errorx"></p:messages>
<h:panelGrid columns="1">
<p:outputLabel value="Anda yakin ingin menghapus #{empGradeBacking.selectedEmp.empGradeName}?"></p:outputLabel>
<h:panelGrid styleClass="reasonDown">
<p:outputLabel value="Alasan "></p:outputLabel>
<p:inputTextarea required="#{param['form:inputtext']==null} true" value="#{empGradeBacking.selectedEmp.deletedReason}" cols="40" rows="5" minQueryLength="1" counter="display" maxlength="200" autoResize="false" counterTemplate="{0} karakter tersisa" validatorMessage="alasan tidak boleh kosong"></p:inputTextarea>
<h:outputText id="display" styleClass="charremaining"></h:outputText>
</h:panelGrid>
</h:panelGrid>
<h:panelGrid styleClass="addDeleteDown" columns="2">
<p:commandButton id="inputtext" ignoreAutoUpdate="true" value="#{UIBundle['text.page.button.yes']}" actionListener="#{empGradeBacking.deleteEmpGrade}" icon="ui-icon-check" oncomplete="if (!args.validationFailed) PF('dlg1').hide()" update="errorx #([id$=empB])"></p:commandButton>
<p:commandButton value="#{UIBundle['text.page.button.no']}" type="button" onclick="PF('dlg1').hide()" icon="ui-icon-close" immediate="true"/>
</h:panelGrid>
</p:dialog>
</p:tab>
</p:tabView>

ignore validation on dialog close jsf primefaces

Iam trying to validate a p:dialog as below
<p:dialog widgetVar="canPolDialog" id="canPolDialog" modal="true"
appendTo="#form:canPolPanel"
focus="name"
resizable="false" draggable="false" minHeight="600" minWidth="250" width="700"
onHide="hideModal()" styleClass="canPolDialog">
<f:facet name="header">
<div class="dialogHeader">
<h2>#{messages['pages.cancellationPolicies.dialog.title']}</h2>
<span>#{messages['pages.cancellationPolicies.dialog.description']}</span>
</div>
</f:facet>
<p:outputPanel id="cancellationDetail"
styleClass="col-md-12 xs-mt-20 dialogSublabel">
<f:validateBean>
<p:outputPanel rendered="#{policyBean.renderCancelationDialog}">
<p:outputPanel id="customPanel">
<f:verbatim escape="false"
rendered="#{policyBean.closePopup}">
<script type="text/javascript">
PF('canPolDialog').hide();
</script>
</f:verbatim>
<div class="row">
<ets:inputTextWithLabel
label="pages.cancellationPolicies.name"
id="name"
formCol="6"
requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.policyName.cant.be.null')}"
value="#{policyBean.cancelationPolicyPojo.name}"
required="true"
/>
</div>
<div class="col-md-10 minsizeText">
#{messages['pages.cancellationPolicies.policyName.description']}
</div>
<div class="row">
<ets:selectWithLabel required="true"
id="policyNameType"
requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.policyNameType.cant.be.null')}"
firstItem="#{messages['global.pleaseSelect']}"
formCol="6"
label="pages.cancellationPolicies.policyName"
value="#{policyBean.cancelationPolicyPojo.policyNameType}">
<f:selectItems noSelectionValue="false"
value="#{PolicyNameType.values()}"
var="nameType"
itemValue="#{nameType}"
itemLabel="#{messages[nameType.getBundleKey()]}"/>
<p:ajax event="change" resetValues="true"
update="#form:cancellationTypePanel,#form:dropdownHour,#form:penaltyRenderArea,#form:noShowPanel"
listener="#{policyBean.onNameTypeChange()}"/>
</ets:selectWithLabel>
</div>
<div class="col-md-10 minsizeText">
#{messages['pages.cancellationPolicies.acceptCancelation.description']}
</div>
<div class="row">
<p:outputPanel id="cancellationTypePanel">
<ets:selectWithLabel
id="cancellationType"
firstItem="#{messages['global.pleaseSelect']}"
formCol="6" required="true"
requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolicy.canType.cant.be.null')}"
label="pages.cancellationPolicies.acceptCancelation"
value="#{policyBean.cancelationPolicyPojo.cancellationType}">
<f:selectItems
value="#{policyBean.cancellationTypes}"
var="var" noSelectionValue="false"
itemValue="#{var}"
itemLabel="#{messages['cancelationPolicyBean.cancelationPolicyPojo.'.concat(var.friendlyName())]}"
/>
<p:ajax resetValues="true" event="change"
listener="#{policyBean.handleCancellationChange}"
update="#form:dropdownHour,#form:penaltyRenderArea"/>
</ets:selectWithLabel>
</p:outputPanel>
<p:outputPanel id="dropdownHour">
<p:outputPanel
rendered="#{policyBean.renderSameDayCanpolOpt}">
<ets:selectWithLabel
id="cancellationValue"
value="#{policyBean.cancelationPolicyPojo.cancellationValue}"
formCol="6" required="true"
requiredMessage="#{messages['pages.cancellationPolicies.pleaseSelectHour']}"
label="pages.cancellationPolicies.sameday">
<f:selectItem itemLabel="00:00"
itemValue="00:00"/>
<f:selectItem itemLabel="01:00"
itemValue="01:00"/>
<f:selectItem itemLabel="02:00"
itemValue="02:00"/>
<f:selectItem itemLabel="03:00"
itemValue="03:00"/>
<f:selectItem itemLabel="04:00"
itemValue="04:00"/>
<f:selectItem itemLabel="05:00"
itemValue="05:00"/>
<f:selectItem itemLabel="06:00"
itemValue="06:00"/>
<f:selectItem itemLabel="07:00"
itemValue="07:00"/>
<f:selectItem itemLabel="08:00"
itemValue="08:00"/>
<f:selectItem itemLabel="09:00"
itemValue="09:00"/>
<f:selectItem itemLabel="10:00"
itemValue="10:00"/>
<f:selectItem itemLabel="11:00"
itemValue="11:00"/>
<f:selectItem itemLabel="12:00"
itemValue="12:00"/>
<f:selectItem itemLabel="13:00"
itemValue="13:00"/>
<f:selectItem itemLabel="14:00"
itemValue="14:00"/>
<f:selectItem itemLabel="15:00"
itemValue="15:00"/>
<f:selectItem itemLabel="16:00"
itemValue="16:00"/>
<f:selectItem itemLabel="17:00"
itemValue="17:00"/>
<f:selectItem itemLabel="18:00"
itemValue="18:00"/>
<f:selectItem itemLabel="19:00"
itemValue="19:00"/>
<f:selectItem itemLabel="20:00"
itemValue="20:00"/>
<f:selectItem itemLabel="21:00"
itemValue="21:00"/>
<f:selectItem itemLabel="22:00"
itemValue="22:00"/>
<f:selectItem itemLabel="23:00"
itemValue="23:00"/>
</ets:selectWithLabel>
</p:outputPanel>
<p:outputPanel
rendered="#{policyBean.renderDaysBeforeCheckinOpt}"
formCol="6">
<ets:inputNumberWithLabel decimalPlaces="0"
required="true"
requiredMessage="#{messages['pages.cancellationPolicies.pleaseAdaysbeforecheckin']}"
label="pages.cancellationPolicies.adaysbeforecheckin"
minValue="0"
formCol="6"
maxValue="30"
styleClass="number-form-control"
id="adaysbeforecheckin"
value="#{policyBean.cancelationPolicyPojo.daysBeforeCheckinValue}">
<p:ajax event="blur"
update="adaysbeforecheckin"/>
</ets:inputNumberWithLabel>
</p:outputPanel>
</p:outputPanel>
</div>
<div
class="col-md-10 minsizeText">#{messages['pages.cancellationPolicies.penaltyCharge.description']}
</div>
<div class="row">
<p:outputPanel id="penaltyRenderArea">
<p:outputPanel>
<ets:selectWithLabel
id="penaltyType" required="true"
requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.penType.cant.be.null')}"
label="pages.cancellationPolicies.penaltyCharge"
formCol="6"
firstItem="#{messages['global.pleaseSelect']}"
value="#{policyBean.cancelationPolicyPojo.penaltyType}"
disabled="#{policyBean.penaltyDisable}">
<f:selectItems
value="#{policyBean.penaltyTypeList}"
var="var"
itemValue="#{var}"
itemLabel="#{messages['cancelationPolicyBean.penalty.'.concat(var.friendlyName())]}"
/>
<p:ajax event="change"
listener="#{policyBean.handlePenaltyChange}"
resetValues="true"
update="#form:dropDownPenalty"/>
</ets:selectWithLabel>
<p:outputPanel id="dropDownPenalty">
<p:outputPanel
rendered="#{policyBean.renderPenaltyTotalPrice}">
<ets:inputNumberWithLabel
formCol="6" required="true"
requiredMessage="#{messages['pages.cancellationPolicies.penaltyValueOfTotalPrice']}"
label="pages.cancellationPolicies.ofTotalPrice"
value="#{policyBean.cancelationPolicyPojo.penaltyValueOfTotalPrice}"
symbol="%"
decimalPlaces="0"
emptyValue="empty"
minValue="0"
id="penaltyValueOfTotalPrice"
styleClass="number-form-control"
maxValue="100">
<p:ajax event="blur"
update="penaltyValueOfTotalPrice"/>
</ets:inputNumberWithLabel>
</p:outputPanel>
</p:outputPanel>
</p:outputPanel>
</p:outputPanel>
</div>
<div
class="col-md-10 minsizeText">#{messages['pages.cancellationPolicies.noShow.description']}
</div>
<div class="row">
<p:outputPanel id="noShowPanel">
<ets:selectWithLabel
id="policyNoShowType"
label="pages.cancellationPolicies.noShow"
requiredMessage="#{readMessage.getValidationMessagesValue('cancellationPolcy.noshow.cant.be.null')}"
firstItem="#{messages['global.pleaseSelect']}"
required="true"
formCol="6" event="change"
value="#{policyBean.cancelationPolicyPojo.policyNoShowType}">
<f:selectItems
value="#{policyBean.cancelationPolicyNoShowTypes}"
var="var" itemValue="#{var}"
itemLabel="#{messages['cancelationPolicyBean.noshow.'.concat(var.friendlyName())]}"/>
</ets:selectWithLabel>
</p:outputPanel>
</div>
<div class="row">
<div class="dialog-footer">
<div class="col-md-12">
<ets:submitButton value="#{messages['global.save']}"
update="#form:canDatatable,#form:cancellationDetail,#form:messages,#form:content"
ajax="true"
process="#form:canPolPanel"
styleClass="btn-info btn pull-right"
action="#{policyBean.saveCancellPolicy()}">
</ets:submitButton>
</div>
</div>
</div>
<p:ajax event="close"
process="#this"
resetValues="true">
</p:ajax>
</p:outputPanel>
</p:outputPanel>
</f:validateBean>
</p:outputPanel>
</p:dialog>
when i submit dialog without filling inputs the validations are executing correctly after that if I close the dialog (gave up, dont want to save modal) because of executed and fail validations I cannot submit parent form due to this issue. Any help will be appreciated!
If your parent form and your dialog are part of the same <h:form> you have to take care of the process attributes of your ajax behaviors. If you process the whole form the input fields in your dialog are also processed even if the dialog is not shown. So take care that you only process the fields outside the dialog.
You could also place your dialog in an own <h:form> (not within the other <h:form>), e.g.
<h:form id="form">
parent form
</h:form>
<h:form id="dialog-form">
<p:dialog ...>
dialog form
</p:dialog>
</h:form>
Then you can use #form within each form. If you want to process or update the other form you can use absolute ids, e.g. ":form" or ":dialog-form".

How to fill popup panel with detailed information from datatable in RichFaces

I am working with RichFaces, and in an form for editing I can't get values of the element that I want to edit,
here is my code:
<!-- <h:outputText value="#{collaborateurBo.getAllCollaborateur().size()}" /> -->
<ui:define name="content">
<center>
<a4j:status onstart="#{rich:component('statPane')}.show()"
onstop="#{rich:component('statPane')}.hide()" />
<h:form id="form">
<a4j:outputPanel id="tableaa" layout="block">
<rich:dataTable value="#{PosteBean.getCollaborateurList()}" var="pr" iterationStatusVar="it" id="table"rows="15">
<rich:column>
<f:facet name="header">#</f:facet> #{it.index} </rich:column>
<rich:column>
<f:facet name="header">Last name</f:facet>
<h:outputText value="#{pr.getNom()}" />
</rich:column>
<rich:column>
<f:facet name="header">First name</f:facet>
<h:outputText value="#{pr.getPrenom()}" />
</rich:column>
<rich:column>
<a4j:commandLink styleClass="no-decor" execute="#this"render="#none"
oncomplete="#{rich:component('confirmPane')}.show()">
<h:graphicImage value="/css/images/delete.gif" alt="delete" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collab}"value="#{p}" />
</a4j:commandLink>
<a4j:commandLink styleClass="no-decor" render="editGrid" execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<h:graphicImage value="/css/images/edit.gif" alt="edit" />
<a4j:param value="#{it.index}"
assignTo="#{PosteBean.currentProjectIndex}" />
<f:setPropertyActionListener target="#{PosteBean.Collab}" value="#{p}" />
</a4j:commandLink>
</rich:column>
<f:facet name="footer">
<rich:dataScroller id="scroller" />
</f:facet>
</rich:dataTable>
<a4j:commandButton styleClass="no-decor" render="addGrid"
oncomplete="#{rich:component('addPane1')}.show()"
value="Add new User">
</a4j:commandButton>
</a4j:outputPanel>
<a4j:jsFunction name="remove" action="Collaborateurr.remove()"
render="tableaa" execute="#this"
oncomplete="#{rich:component('confirmPane')}.hide();" />
<rich:popupPanel id="statPane" autosized="true">
<h:graphicImage value="/css/images/ai.gif" alt="ai" />
Please wait...
</rich:popupPanel>
<rich:popupPanel id="confirmPane" autosized="true">
Are you sure you want to delete the row?
<a4j:commandButton value="Cancel"
onclick="#{rich:component('confirmPane')}.hide(); return false;" />
<a4j:commandButton value="Delete" onclick="remove()" />
</rich:popupPanel>
</h:form>
<rich:popupPanel header="Edit User Details" id="editPane"
domElementAttachment="parent" width="400" height="200">
<h:form id="form2">
<rich:graphValidator id="gvv">
<rich:messages for="gvv" />
<rich:messages globalOnly="true" />
<h:panelGrid columns="3" id="editGrid">
<h:outputText value="nom" />
<h:inputText value="#{PosteBean.collab.nom}" />
<h:panelGroup />
<h:outputText value="prenom" />
<h:inputText value="#{PosteBean.collab.prenom}" />
</h:panelGrid>
<h:selectOneRadio id="koko" value="PosteBean.sflag">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Store" action="PosteBean.store"
render="table" execute="editPane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('editPane')}.hide(); return false;" />
</rich:graphValidator>
</h:form>
</rich:popupPanel>
<rich:popupPanel header="Add User " id="addPane1"
domElementAttachment="parent" width="400" height="200">
<rich:graphValidator id="gv">
<rich:messages for="gv" />
<rich:messages globalOnly="true" />
<h:panelGrid columns="3" id="addGrid">
<h:outputText value="Last name" />
<h:inputText value="#{PosteBean.collab.nom}" />
<h:panelGroup />
<h:outputText value="First name" />
<h:inputText value="#{PosteBean.collab.prenom}" />
<h:panelGroup />
</h:panelGrid>
<h:selectOneRadio id="kokoo" value="#{PosteBean.sflag}">
<f:selectItem itemValue="ROLE_ADMIN" itemLabel="Manager" />
<f:selectItem itemValue="ROLE_USER" itemLabel="Tester" />
</h:selectOneRadio>
<a4j:commandButton value="Add" action="#{PosteBean.add}"
render="table" execute="addPane1"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('addPane1')}.hide();}" />
<a4j:commandButton value="Cancel"
onclick="#{rich:component('addPane1')}.hide(); return false;" />
</rich:graphValidator>
</rich:popupPanel>
</center>
</ui:define>
</ui:composition>
Thanks in advance for helping me, i wanna have values and edit them in the form

Method in actionListener is not invoked after validation failed

I have a command Button that calls a method from the Session Scoped Bean if the inputs are valid.
<h:form id="mainform">
<p:panel id="panelform" header="Email Extractor" >
<h:panelGrid id="formulaire" columns="2">
<h:panelGroup id="formblock" layout="block" >
<p:panelGrid columns="2">
<p:outputLabel for="Keyword" value="Keyword: " />
<p:inputText id="Keyword" type="search" requiredMessage="Keyword is required"
value="#{mailMB.keyword}" required="true" label="Keyword">
</p:inputText>
<p:outputLabel for="Emailsnbr" value="Enter the emails'number:" />
<p:inputText id="Emailsnbr" type="number" requiredMessage="Emails number is required" validatorMessage="Enter a number"
value="#{mailMB.number}" required="true" label="Emailsnbr">
<f:validateDoubleRange minimum="1" maximum="53500" />
</p:inputText>
</p:panelGrid>
</h:panelGroup>
</h:panelGrid>
<p:commandButton value="Extract" style="width: 12%;height: 100%" update="tableemails, :confirmPurchaseTest, :mainform" id="extractbutton" ajax="true" widgetVar="ButtonExtract"
actionListener="#{mailMB.searchEmails()}" onstart="blockUIWidget1.show();" oncomplete=" blockUIWidget1.hide(); if (args && !args.validationFailed) confirmDialog.show();" />
<p:dialog widgetVar="blockUIWidget1" modal="true" closable="false" resizable="false" >
<h:panelGrid columns="2">
<div>
<p:graphicImage url="pictures/loading81.gif" width="200" height="200" alt="animated-loading-bar"/>
<h:outputLabel value="Please wait..."/>
</div>
<div>
<p:button outcome="home" icon="ui-icon-arrowthick-1-w" title="Back To Home" style="margin-right: 5px;white-space: nowrap" />
</div>
</h:panelGrid>
</p:dialog>
</p:panel>
<p:dataTable rowIndexVar="rowIndex" id="tableemails" value="#{mailMB.mails}" var="item" rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true" rows="5" styleClass="case-table" emptyMessage="No records found with given criteria" paginatorPosition="bottom"
filteredValue="#{mailMB.filteredMails}" rowKey="#{item.id}"
selection="#{mailMB.selectedMail}" selectionMode="single" >
<p:ajax event="rowSelect" update=":mainform"/>
<p:column styleClass="blockable">
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
</p:dataTable>
</h:form>
<p:confirmDialog closable="false" style="position: absolute; width: 50px; border-color: blue" id="confirmPurchaseTest" message="Your Database was successfully created. It contains #{mailMB.number} Emails "
appendToBody="true"
header="Get Emails List" severity="info" widgetVar="confirmDialog">
<h:form>
<p:commandButton id="getEmails" style="width: 35%;height: 100%" value="Get Emails" oncomplete="window.location.href = '/Hitonclick/emailsList.xhtml'" >
<f:event type="preRenderView" listener="#{mailMB.preRender}"/>
</p:commandButton>
<p:commandButton id="declineTest" style="width: 35%;height: 100%" value="Decline" onclick="deleteDialog.show();" />
</h:form>
</p:confirmDialog>
My SessionScoped Bean is
#ManagedBean(name = "mailMB")
#SessionScoped
public class MailManagedBean implements Serializable {
#Inject
private MailBusinessLocal mailmanagerLocal;
#Inject
private DataBusinessLocal dataBusinessLocal;
#Inject
private CustomerBusinessLocal customerBusinessLocal;
.....
#PostConstruct
public void init() {
mails = new ArrayList<>();
}
public void searchEmails() throws Exception {
idCustomer = (String) session.getAttribute("idCustomer");
System.out.println(idCustomer + " this is it");
Customer customer = customerBusinessLocal.findById(idCustomer);
data = dataBusinessLocal.createData(new Date(), number, keyword, moteur, customer, State.REJECTED);
mails = mailBusinessLocal.createEmails(keyword, number, moteur, data);
System.out.println("Method was invoked");
}
}
if i enter 0 in the emails's number input for exemple and submit with Extract command Button for the first time i get the validatorMessage So i enter a valid number and submit again. And here comes the problem, the dialog in the oncomplete is shown without invoking the method in the actionListener. I mean i get the confirm dialog of persisted object without invoking the method that persists the object. Am i missing something??
How could i fix that?

Resources