Unable to show faces message on xhtml page - jsf-2

I am unable to show faces messages using facesMessage
Bean code :
if(condition){
FacesContext fc=FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Rounding Rule Saved","R Saved"));
}
View code :
<p:messages autoUpdate="true" showDetail="true" globalOnly="true" id="msgId"/>
But I am not getting messages, what am I doing wrong?
EDIT:
My project flow is :
User click on edit button on view page
Redirect to edit page
After submitting return to view page
Render message(which I am not getting)
View code (rouning_rule_master.xhtml) :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<ui:composition template="/pages/webEx_Template.xhtml">
<ui:define name="content">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rounding Rule Master</title>
<link rel="stylesheet" type="text/css" href="../css/rounding_rule_master.css" />
</h:head>
<h:body>
<div class="wrapper">
<div class="page_wrapper">
<div class="page_heading border_bottom">Rounding Rule Master</div>
<div class="form_div">
<h:form id="roundingMasterFormId" >
<p:messages autoUpdate="true" showDetail="true" globalOnly="true" id="MESSAGEID"/>
<div class="form_detail">
<div class="float_right">
<h:commandButton id="creataeBtn" action="#{roundingBean.createRoundingRule}" value="Create Rounding Rule" class="createRelation" >
<p:ajax onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>
</h:commandButton>
</div>
<div class="clear"></div>
<div style="margin:10px 0;">
<table id="roundingMasterTableId" width="100%" cellspacing="1" cellpadding="0" border="0" class="role_detail_section">
<thead>
<tr>
<th>Rounding Rule Id</th>
<th>Rounding Rule Name</th>
<th>Rounding Mode</th>
<th>Rounding Constant</th>
<th class="action">Action</th>
</tr>
</thead>
<tbody>
<c:forEach items="#{roundingBean.roundingRuleList}" var="var" >
<tr>
<h:inputHidden value="#{var.roundingRuleId}" />
<td><h:outputText value="#{var.roundingRuleId}" /></td>
<td><h:outputText value="#{var.roundingRuleName}" /></td>
<td><h:outputText value="#{var.roundingMode.roundingModeName}" /></td>
<td><h:outputText value="#{var.roundingIncrement}" /></td>
<td>
<p:commandLink value="Edit" styleClass="edit_icon" action="#{roundingBean.editRoundingRule (var,true)}" immediate="true" process="#this" onstart="statusDialog.show();" onsuccess="statusDialog.hide();">
</p:commandLink>
<p:commandLink id="deleteId" styleClass="remove_icon" action="#{roundingBean.deleteRoundingRule(var.roundingRuleId)}" immediate="true" update="#form" process="#this" oncomplete="addCSS()" onstart="statusDialog.show();" onsuccess="statusDialog.hide();">
<p:confirm header="Confirmation" message="Are you sure want to delete rounding rule ?" icon="ui-icon-alert" />Delete
</p:commandLink>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
<p:confirmDialog styleClass="confirm" global="true" showEffect="fade" draggable="false" closable="false" resizable="false" width="400">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes"/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no"/>
</p:confirmDialog>
<p:dialog styleClass="confirm" modal="true" widgetVar="statusDialog" header="Loading..."
draggable="false" closable="false" resizable="false" width="100"
height="50">
<div align="center">
<p:graphicImage value="../images/loading.gif" width="50"
height="50" />
</div>
</p:dialog>
</h:form>
</div>
</div>
</div>
</h:body>
</ui:define>
</ui:composition>
</html>

I am not sure if it is your case. But if you redirect after generating the Messages, they are lost in the redirect process. You need to make sure there is no redirect in the faces config - or any other mean - in your page flow.

Related

rich:popupPanel with <a4j:status> is not working in JSF2

When i hit on Submit button rich popup panel is not working.Should it be outside the h:form or inside . I tried both ways but it is not working. Please help me where i am going wrong .Below is my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:body>
<ui:composition template="/pages/layout.xhtml">
<ui:define name="heading">
<h:outputText value="Paging” </h:outputText>
</ui:define>
<ui:define name="content">
<h:panelGrid id="panel2">
<h:form id="my_form">
<table>
<tr>
<td>
<h:panelGroup id="globalmessages">
<h:message id="key1" for="key" style="color:red" showDetail="true" />
<h:message id="lock1" for="lock" errorStyle ="color:red" showDetail="true" />
</h:panelGroup>
</td>
</tr>
</table>
<table width="700px" >
<tr>
<td align="right" width="30%"><label>Files: </label></td>
<td align="left" width="70%"><h:outputText value= "Hosting file" /></td>
</tr>
<tr>
<td align="right" width="30%"><label for="lastdate">
Last Date:</label></td>
<td align="left" width="70%"><h:panelGrid id="panel1">
<h:panelGroup>
<rich:calendar id=" lastdate "
value="#{myBean.ladate}"
locale="Locale.US" popup="true" datePattern="MM/dd/yyyy"
showApplyButton="false" todayControlMode = "hidden" cellWidth="24px" cellHeight="220px"
enableManualInput = "true" converterMessage = "Entered wrong date format"
style="width:200px" required="true" requiredMessage="Last date: is required."/>
(MM/DD/YYYY)
</h:panelGroup>
</h:panelGrid>
<h:commandButton value ="getHost" action="#{mybean.hosted}" id="key" />
</td>
</tr>
<tr></tr><tr></tr><tr></tr><tr></tr>
<tr>
<td align="right" width="30%"><label>Data: </label></td>
<td align="left" width="70%"><h:inputText id="datarelated" value="#{myBean.dataExist}" style="padding-bottom: 68px; width: 165px;"/></td>
</tr>
<tr></tr><tr></tr><tr></tr>
<tr>
<td align="right">
<a4j:commandButton value ="SubmitVal" action="#{myBean.onVal}" id="lock" style="height: 25px; width: 90px;"
render="globalmessages" status="ajaxStatus"/>
</td>
</tr>
</table>
</h:form>
<a4j:status name="ajaxStatus"
onstart="#{rich:component('waitPanel')}.show('',{top:'340px', left:'450px',height:'50px', width:'350px'})"
onstop="#{rich:component('waitPanel')}.hide()" >
</a4j:status>
<rich:popupPanel id="waitPanel" style="text-align:center">
<h:form id="test">
<h:outputText value="Please wait...Calculating" style="font-weight:bold;font-size:large" />
</h:form>
</rich:popupPanel>
</h:panelGrid>
</ui:define>
</ui:composition>
</h:body>
</html>

p:commandButton p:confirm actionListener not triggering

Primefaces actionListener is not working in p:confirmDialog . Can someone help? The saveRecord works fine in a simple dialog box.
<p:commandButton value="Save" actionListener="#{EmployeeDetailsComponent.displayInfo}">
<p:confirm header="Attention" message="test" icon="ui-icon-alert" />
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" appendToBody="true">
<p:commandButton value="Save" action="#{TestComponent.saveRecord(TestComponent.testData)}" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
You have appendToBody="true", which means there is no <h:form> to handle the click because the whole dialog content is moved directly under body. Just add the form inside the dialog.
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" appendToBody="true">
<h:form>
<p:commandButton value="Save" action="#{TestComponent.saveRecord(TestComponent.testData)}" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
I just add a div to center the buttons and the process and the action works perfectly, example code with primefaces 5.1:
<p:confirmDialog global="true" showEffect="clip" >
<div align="center">
<p:commandButton value="Aceptar" actionListener="#{bienvenidoUI.asignarPSI()}" update="tablaProceso" icon="ui-icon-check" process="#this" styleClass="ui-confirmdialog-yes"/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</div>
</p:confirmDialog>
and I just call the confirmDialog from inside a table with:
<p:commandButton icon="ui-icon-circle-check" title="Asignar PSI" rendered="#{bienvenidoUI.usr.idUsuario==bienvenidoUI.autorizadorId and min.estado.descripcion=='Proceso'}">
<f:setPropertyActionListener value="#{min}" target="#{bienvenidoUI.minutaSelected}" />
<p:confirm header="Confirmación" message="Esta seguro que desea asignar psi?" icon="ui-icon-alert" />
</p:commandButton>
remove appendToBody="true" from the confirm dialog component and enclose Save command buttton with in form.
<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<html lang="en">
<h:head>
</h:head>
<h:body id="top">
<h:form>
<p:commandButton value="Save" actionListener="#{simpleBean.displayInfo}" action="#{simpleBean.saveRecord}">
<p:confirm header="Attention" message="test" icon="ui-icon-alert" />
</p:commandButton>
</h:form>
<p:confirmDialog closeOnEscape="true" global="true" showEffect="fade" hideEffect="explode">
<p:commandButton value="Save" type="button" styleClass="ui-confirmdialog-yes"/>
<p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no"/>
</p:confirmDialog>
</h:body>
</html>
</f:view>
SimpleBean.java
#Named("simpleBean")
public class SimpleBean implements Serializable{
public void displayInfo(){
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Display Info works");
}
public String saveRecord(){
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Save Record works");
return null;
}
}

Primefaces Mobile Navigation/Render after submit commandButton

I am new to mobile development and have trouble rendering a pm:page after invoking a method on managed bean.
My page has a primefaces overlaypanel with a button to search and a datatable for display the result.
The method is invoked correctly but the page with the outcome is never displayed (pm:page id="resultados").
The method is very simple and only assembles a list of Strings.
According to the primefaces user guide and searching the internet, I tried the following
I've tested it with PrimeFaces 5.0 and 5.1
<!-- action + actionListener -->
<p:commandButton id="search1"
value="search 1"
actionListener="#{myMB.search}"
action="pm:resultados"
update="#all" /> <!-- ????? -->
<!-- client API onComplete -->
<p:commandButton id="search2"
value="search 2"
action="#{myMB.search}"
onComplete="PrimeFaces.Mobile.navigate('#pm:resultados', {reverse: false, transition: 'fade'});"
update="#all" /> <!-- ????? -->
<!-- action + return -->
<p:commandButton id="search3"
value="search 3"
action="#{myMB.searchMobile}"
update="#all"/> <!-- ????? -->
Below is the full source code
#ManagedBean(name="myMB")
#ViewScoped
public class MyMB implements Serializable {
private List<String> lista = new ArrayList<String>();
public void search() {
for(int i = 1; i <= 10; i++) {
lista.add("" + i);
}
}
public String searchMobile() {
for(int i = 10; i <= 20; i++) {
lista.add("" + i);
}
return "pm:resultados";
}
public List<String> getLista() {
return lista;
}
public void setLista(List<String> lista) {
this.lista = lista;
}
}
xhtml page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pm="http://primefaces.org/mobile">
<f:view renderKitId="PRIMEFACES_MOBILE" />
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:form id="formMobile" prependId="false">
<pm:page id="pmTopo">
<pm:content>
<div id="divTop">
<h:panelGrid columns="1">
<h:panelGroup layout="block">
<p:commandLink id="linkFiltros">
<p:graphicImage library="imagens" name="filter-mobile.png" id="filterIMG" />
</p:commandLink>
<p:commandLink id="linkMenu">
<p:graphicImage library="imagens" name="menu-mobile.png" id="menuIMG"/>
</p:commandLink>
<p:graphicImage library="imagens" name="image1.png" id="logoIMG"/>
</h:panelGroup>
</h:panelGrid>
</div>
<div id="divFilter">
<p:overlayPanel for="linkFiltros" widgetVar="painelFiltros" at="left" showEffect="overlay">
<h:panelGrid columns="1">
<p:commandButton id="search1"
value="search 1"
actionListener="#{myMB.search}"
action="pm:resultados"
update="#all" /> <!-- ????? -->
<p:commandButton id="search2"
value="search 2"
action="#{myMB.search}"
onComplete="PrimeFaces.Mobile.navigate('#pm:resultados', {reverse: false, transition: 'fade'});"
update="#all" /> <!-- ????? -->
<p:commandButton id="search3"
value="search 3"
action="#{myMB.searchMobile}"
update="#all"/> <!-- ????? -->
</h:panelGrid>
</p:overlayPanel>
</div>
</pm:content>
</pm:page>
<pm:page id="resultados">
<pm:content>
<div id="divConteudo">
<p:growl id="mensagemMobile"
showDetail="true"
showSummary="false"
autoUpdate="true" />
<p:dataTable id="tableResult"
var="item"
value="#{myMB.lista}"
widgetVar="tabela">
<p:column headerText="Column 1" priority="1">
<h:outputText value="#{item}" />
</p:column>
</p:dataTable>
</div>
</pm:content>
</pm:page>
</h:form>
</h:body>
</html>
The problem occurred due to errors in the attribute "update" in commandButton.
The correct approach is
<p:commandButton id="botao1" value="search" actionListener="#{myMB.search}" action="pm:resultados"
update=":resultados:formMobile:tabelaTeste" />
The entire page was so
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pm="http://primefaces.org/mobile">
<f:view renderKitId="PRIMEFACES_MOBILE" />
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<pm:page id="principal">
<pm:content>
<h:form id="formMobile" prependId="false">
<h:panelGrid columns="1">
<p:commandButton id="search1"
value="Search"
actionListener="#{myMB.search}"
action="pm:resultados"
update=":resultados:formMobile:tabelaTeste" />
</h:panelGrid>
</h:form>
</pm:content>
</pm:page>
<pm:page id="resultados">
<pm:header> Resultados </pm:header>
<pm:content>
<h:form id="formMobile" prependId="false">
<p:button outcome="pm:principal" value="Back" />
<div id="divConteudo">
<p:growl id="mensagemMobile"
showDetail="true"
showSummary="false"
autoUpdate="true" />
<p:dataTable id="tabelaTeste"
var="item"
value="#{myMB.lista}"
widgetVar="tabela"
tableStyleClass="ui-responsive ui-table table-stripe ui-table-columntoggle">
<p:column headerText="valor" priority="1">
<h:outputText value="#{item}" />
</p:column>
</p:dataTable>
</div>
</h:form>
</pm:content>
</pm:page>
</h:body>
</html>

Primefaces p:dialog does not showing up

I am trying show within the p:dialog-element the p:fileUpload- Element.
Without the p:fileUpload -Element the p:dialog is showing up. Then I add the fileUpload-Tag
and it does nothing. I am using Tomcat 7, mojorra 2.1.28, primefaces 5.0.
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
template="WEB-INF/templates/template.xhtml"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<!--Zusätzliches Stylesheet-->
<ui:define name="additionalCSS"> <link rel="stylesheet" type="text/css" href="resources/style/benutzer.css" /> </ui:define>
<!--Titel-->
<ui:define name="title">Ticket schreiben</ui:define>
<!--Hier beginnt der Content-Bereich, der je nach Client variiert-->
<ui:define name="content">
<div id="content">
<div id="verlauf">
<h:form>
<h:commandLink value="Home" action="#{linkController.goHome}"> </h:commandLink> /
<h:commandLink value="Tickets" action="#{linkController.goTicketindex}"></h:commandLink> /
<h:commandLink value="Neues Ticket erstellen" action="#{linkController.goTicketcreate}"></h:commandLink>
</h:form>
</div>
<div id="headline">Neues Ticket erstellen</div>
<h:form>
<div id="stats">
<div id="title">Empfänger</div>
<div class="inputName">An:</div>
<div class="inputContent"> <h:inputText id="user" styleClass="inputText" value="#{ticketController.adress}" >
<!-- validatorMessage="Bitte geben Sie den Empfänger an." >
<f:validateRequired/>-->
</h:inputText> </div>
<div class="inputName">Betreff:</div>
<div class="inputContent"> <h:inputText id="topic" styleClass="inputText" value="#{ticketController.topic}"
></h:inputText> </div>
</div>
<div id="rechte">
<div id="title">Nachricht</div>
<div class="column">
<div class="inputArea"> <h:inputTextarea id="message" styleClass="inputField" value="#{ticketController.message}" >
<!-- validatorMessage="Bitte geben Sie eine Nachricht ein." >
<f:validateRequired/>-->
</h:inputTextarea> </div>
</div>
<br/>
<p:dialog widgetVar="dialogVar" modal="true" minHeight="100" draggable="true" >
<p:fileUpload fileLimit="20000" fileLimitMessage="File ist zu groß" fileUploadListener="#{ticketController.fileUploadHandler}"></p:fileUpload>
</p:dialog>
<h:commandButton value="Datei Uploaden" type="button" styleClass="submitButton" onclick="dialogVar.show()"></h:commandButton>
<h:commandButton value="Anlegen" type="submit" styleClass ="submitButton"
action="#{ticketController.createNewTicket}"></h:commandButton>
</div>
</h:form>
</div>
</ui:define>
</ui:composition>
I tried PF('dialogVar').show and dialogVar.show(), but it is not showing up.
I think you must add inside your dialog. After generating code,despite what you see in your xhtml page, the dialog will be outside of your form,therefore you need to add it yourself.
try the following code:
<ui:define name="content">
<div id="content">
<div id="verlauf">
<h:form>
<h:commandLink value="Home" action="#{linkController.goHome}"/>
<h:commandLink value="Tickets" action="#{linkController.goTicketindex}"/>
<h:commandLink value="Neues Ticket erstellen" action="#{linkController.goTicketcreate}"/>
</h:form>
</div>
<div id="headline">Neues Ticket erstellen</div>
<h:form>
<div id="stats">
<div id="title">Empfänger</div>
<div class="inputName">An:</div>
<div class="inputContent">
<h:inputText id="user" styleClass="inputText" value="#{ticketController.adress}" />
</div>
<div class="inputName">Betreff:</div>
<div class="inputContent">
<h:inputText id="topic" styleClass="inputText" value="#{ticketController.topic}"
></h:inputText> </div>
</div>
<div id="rechte">
<div id="title">Nachricht</div>
<div class="column">
<div class="inputArea"> <h:inputTextarea id="message" styleClass="inputField" value="#{ticketController.message}" >
<!-- validatorMessage="Bitte geben Sie eine Nachricht ein." >
<f:validateRequired/>-->
</h:inputTextarea> </div>
</div>
<br/>
<h:commandButton value="Datei Uploaden" type="button" styleClass="submitButton" onclick="dialogVar.show()"></h:commandButton>
<h:commandButton value="Anlegen" type="submit" styleClass ="submitButton"
action="#{ticketController.createNewTicket}"></h:commandButton>
</div>
</h:form>
<p:dialog widgetVar="dialogVar" modal="true" minHeight="100" draggable="true" >
<h:form>
<p:fileUpload fileLimit="20000" appendToBody="false" fileLimitMessage="File ist zu groß" fileUploadListener="#{ticketController.fileUploadHandler}"/>
</h:form>
</p:dialog>
</div>

To display validation message in primefaces dialog from managed bean

i am trying to display the message of the outcome of a validation done in managed bean in the dialog but it is not getting displayed in the dialog on submit of the form.
Please help me in fixing this
My JSF page snippet with dialog
<p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
appendToBody="true" resizable="true" modal="true" height="320px"
width="38%">
<h:form id="addLpc">
<div align="center" style="margin-bottom: 1px; padding-bottom: 1px;">
<h:outputLabel value="Add New LPC"
style="font-color:#000000;font-weight:bold;font-size:24px;padding-bottom:1px;"></h:outputLabel>
</div>
<div align="center">
<p:messages id="lpcDlgMsg" showDetail="false" autoUpdate="true"
closable="true" />
<p:messages id="lpcDlgMsg2" for="lpcDlgMessage" showDetail="false"
autoUpdate="true" closable="true" />
<h:panelGrid id="addLpcForm" columns="2" appendToBody="true">
<h:outputText value="LPC ID" />
<p:inputText id="lpcId" value="#{lpcBean.lpcId}" required="true"
requiredMessage="LPC ID is required">
<f:ajax event="blur" render="lpcDlgMsg" />
</p:inputText>
<h:outputText value="First Name" />
<p:inputText id="firstName" value="#{lpcBean.firstName}" />
.
.
.
.
</h:panelGrid>
</div>
<div align="center">
<p:commandButton id="submitButton" value="Submit" ajax="true"
update=":lpcForm:lpcDataTable,addLpc"
action="#{lpcBean.formSubmit}" oncomplete="dlg.hide()" />
<p:commandButton id="cancelButton" value="Cancel"
onclick="dlg.hide()" />
</div>
</h:form>
</p:dialog>
message with id lpcDlgMsg2 is the message i am trying to display on submit.The other message is getting displayed correct on blur.
Snippet of the method that is called on submit
public void formSubmit()
{
if(resultSet.next())
{
int lpcIdCount=rs.getInt("lpcCount");
if(lpcIdCount!=0)
{
FacesContext.getCurrentInstance().addMessage("lpcDlgMessage", new FacesMessage(FacesMessage.SEVERITY_ERROR," ", "Duplicate LPCID"));
System.out.println("after display");
}
else
{
.
.
.
.
}
}
}
}
Here is my suggestion:
<p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
appendToBody="true" resizable="true" modal="true" height="320px"
width="38%">
<h:form id="addLpc">
<div align="center">
<p:messages id="lpcDlgMsg" showDetail="false" autoUpdate="true"
closable="true" />
<h:panelGrid id="addLpcForm" columns="2" >
<h:outputText value="LPC ID" />
<p:inputText id="lpcId" required="true" />
<h:outputText value="First Name" />
<p:inputText id="firstName" required="true" />
</h:panelGrid>
</div>
<div align="center">
<p:commandButton id="submitButton" value="Submit"
oncomplete="if (!args.validationFailed){dlg.hide();}" />
<p:commandButton id="cancelButton" value="Cancel"
onclick="dlg.hide()" />
</div>
</h:form>
</p:dialog>
Note that I've simplified your code in order to avoid using a managedbean.
If you want your managed bean to perform the validation, use RequestContext to conditionally execute the code that will close the dialog and remove the oncomplete from Submit button.
if (success) {
RequestContext.getCurrentInstance().execute("dlg.hide()");
}else{
//show all the messages you need here
}
You have to add this javascript first inside head tag
function handleComplete(xhr, status, args) {
if (!args.validationFailed) {
dlg.hide();
} else {
}
}
More changes are
<p:commandButton id="submitButton" value="Submit" ajax="true"
update=":lpcForm:lpcDataTable,addLpc :lpcDlgMsg2"
actionListener="#{lpcBean.formSubmit}" oncomplete="handleComplete(xhr, status, args)" />
action to actionListener because action has String return type.
This will work fine.

Resources