PrimeFaces - Validation error in 2nd dropdown (dependent selectOneMenus) - RequestScoped - ajax

The 2nd dropdown is being populated by AJAX, but there's validation error in it. Even if the list is populated correctly and a selection is made.
<h:form id="form">
<p:growl id="growl" showDetail="true" sticky="true" globalOnly="true" />
<h:panelGrid columns="3">
<p:outputLabel for="nome" value="Nome:" />
<p:inputText id="nome" value="#{estadoMB.estado.nome}" required="true" validatorMessage="Nome incorreto!" />
<p:message for="nome" />
<p:outputLabel for="sigla" value="Sigla:" />
<p:inputText id="sigla" value="#{estadoMB.estado.sigla}" maxlength="3" size="3" required="true" validatorMessage="Sigla incorreta!" />
<p:message for="sigla" />
<p:outputLabel for="continentes" value="Continente:" />
<p:selectOneMenu id="continentes" value="#{estadoMB.continenteId}" validatorMessage="Selecione um continente!"> <!-- required="# {not empty param[submit.clientId]}" binding="# {menuContinentes}" -->
<f:selectItem itemValue="" itemLabel="-- Selecione --" noSelectionOption="true" />
<f:selectItems value="#{continenteMB.continentes}" var="continente" itemLabel="#{continente.nome}" itemValue="#{continente.id}" />
<p:ajax event="change" listener="#{estadoMB.onPaisesChange}" update="paises" />
</p:selectOneMenu>
<p:message for="continentes" />
<p:outputLabel for="paises" value="País:" />
<p:selectOneMenu id="paises" value="#{estadoMB.pais.id}" validatorMessage="Selecione um país!"> <!-- required="# {not empty param[menuContinentes.clientId]or not empty param[submit.clientId]}" -->
<f:selectItem itemValue="" itemLabel="-- Selecione --" noSelectionOption="true" />
<f:selectItems value="#{estadoMB.paisesCarregados}" var="pais" itemLabel="#{pais.nome}" itemValue="#{pais.id}" />
</p:selectOneMenu>
<p:message for="paises" />
<p:commandButton action="#{estadoMB.save}" value="Salvar" update="#form" /> <!-- binding="# {submit}" -->
</h:panelGrid>
</h:form>
Method onPaisesChange:
public void onPaisesChange() {
if(pais != null) {
Map<String, Object> map = new HashMap<>();
map.put("id", getContinenteId());
paisesCarregados = paisBean.findWithNamedQuery("Pais.findByContinenteId", map);
}
else {
paisesCarregados = new ArrayList<>();
}
}
Already tried EL binding; required="true" in both and I got the same result.
I think it's not possible to do what I want using request scoped beans...

Related

My form inside a dialog keeps values when i re-open dialog

i am using a form inside a dialog to edit some data , i use setPropertyActionListener tag to get this data from a dataTable , my form shows correctly all fields , but when i change some data and close the dialog and reopen it (without submuting) the form keeps the latest data and ignore what is coming from setPropertyActionListener
here is my code used to open the dialog
<p:menuButton value="Actions">
<p:menuitem resetValues="true" value="Update"
icon="fa fa-edit" process="#this"
actionListener="#{myMB.resetSelectedEntite(a)}"
update="formUpdateAff:displayEditionAff"
oncomplete="PF('affUpdateDialogWidget').show()">
<f:setPropertyActionListener
target="#{myMB.selectedAffectation}" value="#{a}" />
<f:actionListener
type="com.dummy.AffActionListener" />
</p:menuitem>
code for dialog :
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<p:dialog widgetVar="affUpdateDialogWidget" id="affEditerDialogId"
width="30%" showEffect="explode" hideEffect="explode" modal="true">
<h:form id="formUpdateAff" prependId="true">
<p:panel style="margin-bottom:20px;float:center"
widgetVar="titlePanelWidget" collapsed="true"
styleClass="customTitleBar">
<f:facet name="header">
Update
</f:facet>
</p:panel>
<p:tooltip position="top" />
<h:panelGrid id="displayEditionAff" columns="3" cellpadding="4">
<p:outputLabel value="" />
<h:inputHidden value="#{myMB.selectedAffectation.id}" id="idAff" />
<p:message for="idAff" display="tooltip" />
<p:outputLabel value="Date Aff :" for="dateAffectId" />
<p:calendar value="#{myMB.selectedAffectation.dateAff}"
id="dateAffectId" pattern="dd/MM/yyyy" yearRange="c-10:c+0"
showButtonPanel="true" converter="primefacesCalendarConverter"
required="true" locale="fr" showOn="button" />
<p:message for="dateAffectId" display="tooltip" />
<p:outputLabel value="Ville :" for="villeIdAff" />
<p:selectOneMenu style="width:100%; font-weight:bold"
required="true" id="villeIdAff" appendTo="#this"
value="#{myMB.selectedAffectation.refCompagnie.refGroupement.refVille.id}"
rendered="#{myMB.selectedAffectation.refCompagnie.id != 0}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems value="#{lieuUnitMB.selectLieuxByType('VILLE',0)}"
var="a" itemValue="#{a.id}" itemLabel="#{a.libelle}" />
<p:ajax
listener="#{myMB.loadGroupements(myMB.selectedAffectation.refCompagnie.refGroupement.refVille.id , myMB.selectedAffectation.refCompagnie.refGroupement.refCatGroupement.id)}"
update="groupIdAff groupIdxxx" />
</p:selectOneMenu>
<p:selectOneMenu style="width:100%; font-weight:bold"
rendered="#{myMB.selectedAffectation.refCompagnie.id == 0}"
required="true" id="villeId2" appendTo="#this"
value="#{myMB.selectedAffectation.refGroupement.refVille.id}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems value="#{lieuUnitMB.selectLieuxByType('VILLE',0)}"
var="a" itemValue="#{a.id}" itemLabel="#{a.libelle}" />
<p:ajax
listener="#{myMB.loadGroupements(myMB.selectedAffectation.refGroupement.refVille.id , myMB.selectedAffectation.refGroupement.refCatGroupement.id)}"
update="groupIdAff groupIdxxx" />
</p:selectOneMenu>
<p:message for="villeId2" display="tooltip" />
<p:outputLabel value="Catégorie Groupement :" for="catIdAff" />
<p:selectOneMenu style="width:100%; font-weight:bold"
required="true" id="catIdAff" appendTo="#this"
value="#{myMB.selectedAffectation.refGroupement.refCatGroupement.id}"
rendered="#{myMB.selectedAffectation.refCompagnie.id == 0}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems value="#{repositoryMB.selectRepositories()}" />
<p:ajax
listener="#{myMB.loadGroupements(myMB.selectedAffectation.refGroupement.refVille.id , myMB.selectedAffectation.refGroupement.refCatGroupement.id)}"
update="groupIdAff groupIdxxx" />
</p:selectOneMenu>
<p:selectOneMenu style="width:100%; font-weight:bold"
required="true" id="catId2" appendTo="#this"
value="#{myMB.selectedAffectation.refCompagnie.refGroupement.refCatGroupement.id}"
rendered="#{myMB.selectedAffectation.refCompagnie.id != 0}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems value="#{repositoryMB.selectRepositories()}" />
<p:ajax
listener="#{myMB.loadGroupements(myMB.selectedAffectation.refCompagnie.refGroupement.refVille.id , myMB.selectedAffectation.refCompagnie.refGroupement.refCatGroupement.id)}"
update="groupIdAff groupIdxxx" />
</p:selectOneMenu>
<p:message for="catIdAff" display="tooltip" />
<p:outputLabel value="Groupement :" for="groupIdAff" />
<p:selectOneMenu
value="#{myMB.selectedAffectation.refCompagnie.refGroupement.id}"
style="width:100%; font-weight:bold" required="true"
id="groupIdAff" appendTo="#this"
rendered="#{myMB.selectedAffectation.refCompagnie.id != 0}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems
value="#{myMB.loadGroupements(myMB.selectedAffectation.refCompagnie.refGroupement.refVille.id , myMB.selectedAffectation.refCompagnie.refGroupement.refCatGroupement.id)}" />
<p:ajax
listener="#{myMB.loadCompagniesUpdate(myMB.selectedAffectation.refGroupement.id)}"
update="displayEditionAff,toto" />
</p:selectOneMenu>
<p:selectOneMenu
value="#{myMB.selectedAffectation.refGroupement.id}"
style="width:100%; font-weight:bold" required="true"
id="groupIdxxx" appendTo="#this"
rendered="#{myMB.selectedAffectation.refCompagnie.id == 0}">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems
value="#{myMB.loadGroupements(myMB.selectedAffectation.refGroupement.refVille.id , myMB.selectedAffectation.refGroupement.refCatGroupement.id)}" />
<p:ajax
listener="#{myMB.loadCompagniesUpdate(myMB.selectedAffectation.refGroupement.id)}"
update="displayEditionAff,toto" />
</p:selectOneMenu>
<p:message for="groupIdAff" display="tooltip" />
<p:outputLabel value="Compagnie :" for="toto"
binding="#{myMB.uiOutputLabel}"
rendered="#{not empty myMB.compagniesUpdate}" />
<p:selectOneMenu binding="#{myMB.uiOutput}"
rendered="#{not empty myMB.compagniesUpdate}"
value="#{myMB.selectedAffectation.refCompagnie.id}"
style="width:100%; font-weight:bold" required="false" id="toto"
appendTo="#this" immediate="true">
<f:selectItem itemLabel="----------------" itemValue="" />
<f:selectItems
value="#{myMB.loadCompagniesUpdate(myMB.selectedAffectation.refGroupement.id)}" />
</p:selectOneMenu>
<p:message for="toto" display="tooltip"
rendered="#{not empty myMB.compagniesUpdate}"
binding="#{myMB.uiOutputMsg}" />
</h:panelGrid>
<p:spacer />
<p:spacer />
<h:panelGrid columns="2">
<p:commandButton value="Editer" icon="ui-icon-plus"
action="#{myMB.updateEntite()}"
update=":entiteDetailDialogForm:tabsId:formAff:AffTable :messageGrowl :formUpdateAff"
process=":formUpdateAff"
oncomplete="closeDialogIfSucess(xhr, status, args, 'AffUpdateDialogWidget', 'AffEditerDialogId')" />
<p:commandButton value="#{bundle.cancel}" icon="ui-icon-cancel"
actionListener="#{myMB.resetSelectedEntite()}" type="button"
onclick="PF('AffUpdateDialogWidget').hide();" />
</h:panelGrid>
</h:form>
</p:dialog>
</h:body>
</html>
i am using Primefaces 6.1

How to enable my radiobutton with primefaces

enable/disable my selectOneRadio does not work like expected. It only activates after a "submit" and the ajax-direct approach does not work.
When I change the selection (click) to "Group", then the dropDown after the selection keeps being "disabled". It only appears after a "submit", but I like to have direct-ajax function.
<div>
<p:outputPanel id="customPanel" style="margin-bottom:10px">
<p:selectOneRadio id="locationType" value="#{bean.query.locationType}"
required="true" layout="custom">
<f:ajax render="locationGroup locationOrganization">
<f:selectItems value="#{bean.locationTypeSelectItems}"
var="locationTypeItem" itemValue="#{locationTypeItem}" itemLabel="#{msgs[locationTypeItem.label]}" />
</f:ajax>
</p:selectOneRadio>
<h:panelGrid columns="3" cellpadding="5">
<p:radioButton id="option1" for="locationType" itemIndex="0" />
<p:outputLabel for="locationGroup" value="Group"/>
<p:autoComplete id="locationGroup"
value="#{bean.query.locationGroup}"
completeMethod="#{bean.completeGroups}"
var="group"
itemLabel="#{group.description}"
itemValue="#{group}"
converter="org.company.project.presentation.group.GroupConverter"
maxResults="10"
dropdown="true"
cache="true"
disabled="#{bean.locationGroupDisabled}"/>
<p:radioButton id="option2" for="locationType" itemIndex="1" />
<p:outputLabel for="locationOrganization" value="#{msgs.pat_Organization}"/>
<p:autoComplete id="locationOrganization"
value="#{bean.query.locationOrganization}"
completeMethod="#{bean.completeOrganizations}"
var="organization"
itemLabel="#{organization.name}"
itemValue="#{organization}"
converter="org.company.project.presentation.organization.OrganizationConverter"
maxResults="10"
dropdown="true"
cache="true"
disabled="#{bean.locationOrganizationDisabled}"/>
<p:radioButton id="option3" for="locationType" itemIndex="2" />
<p:outputLabel value="All" />
</h:panelGrid>
<p:message for="locationGroup" />
<p:message for="locationOrganization" />
</p:outputPanel>
<p:message for="locationType" />
That's all folks!

How I can change the value of "selectOneMenu" without restart the "inputText"?

I have the next code:
<h:form id="form" >
<h:panelGrid >
<p:inputText placeholder="Name" value="#{controladorGestionGrados.otherValue}" />
<p:selectOneMenu value="#{controladorGestionGrados.value}" >
<f:selectItem itemValue="A" itemLabel="A" />
<f:selectItem itemValue="B" itemLabel="B" />
<f:selectItem itemValue="C" itemLabel="C" />
<p:ajax update=":form" />
</p:selectOneMenu>
<p:outputLabel id="someText"
value="Some text"
rendered="#{controladorGestionGrados.value eq 'C'}" />
</h:panelGrid>
</h:form>
First: I write anything in the inputText.
Second: I select option C.
After, the outputLabel "Some text" is displayed, but the inputText is reseted.
How I can change the value of "selectOneMenu" without restart the "inputText"?
I've tried:
<p:ajax update="someText" />
But effectively the inputText don't reset, but outLabel don't show.
Wrap your <p:outputLabel>
<p:outputLabel id="someText" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
with a holder <p:outputPanel>
Like this :
<p:outputPanel id="someTextPanel">
<p:outputLabel id="someTextLabel" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
</p:outputPanel>
And update the holder component (<p:outputPanel>) with
<p:ajax update="someTextPanel" />
So entire code should be something like this :
<h:form id="form" >
<h:panelGrid >
<p:inputText placeholder="Name" value="#{controladorGestionGrados.otherValue}" />
<p:selectOneMenu value="#{controladorGestionGrados.value}" >
<f:selectItem itemValue="A" itemLabel="A" />
<f:selectItem itemValue="B" itemLabel="B" />
<f:selectItem itemValue="C" itemLabel="C" />
<p:ajax update="someTextPanel" />
</p:selectOneMenu>
<p:outputPanel id="someTextPanel">
<p:outputLabel id="someTextLabel" value="Some text" rendered="#{controladorGestionGrados.value eq 'C'}" />
</p:outputPanel>
</h:panelGrid>
</h:form>

Disable one dropdown when a specific option of another is selected

I have two dropdowns in one form. The first contains those options:
String[] decisions = {"acceptée", "rejettée"};
When "rejettée" is selected, I would like to disable the second dropdown.
Here is the relevant code of the two dropdowns:
<p:selectOneMenu required="true" requiredMessage="veuillez choisir une decision" id="dec" value="#{editCommandController.myCom.decision}">
<f:selectItems value="#{editCommandController.decisions}" />
</p:selectOneMenu>
<p:selectOneMenu id="etat" value="#{editCommandController.myCom.etat}">
<f:selectItems value="#{editCommandController.etats}" />
</p:selectOneMenu>
How can I achieve this?
Try this:
<h:outputLabel for="dec" value="Decision : " />
<p:selectOneMenu required="true"
requiredMessage="veuillez choisir une decision" id="dec"
value="#{editCommandController.myCom.decision}">
<f:selectItems value="#{editCommandController.decisions}" />
<p:ajax update="etat" event="change"/>
</p:selectOneMenu>
<p:message for="dec" display="icon" />
<h:outputLabel for="etat" value="Etat : " />
<p:selectOneMenu id="etat" value="#{editCommandController.myCom.etat}" disabled="#{editCommandController.myCom.decision eq 'rejettée'}">
<f:selectItems value="#{editCommandController.etats}" />
</p:selectOneMenu>
<p:message for="etat" display="icon" />
To set to some default value on change, try this:
<h:outputLabel for="dec" value="Decision : " />
<p:selectOneMenu required="true"
requiredMessage="veuillez choisir une decision" id="dec"
value="#{editCommandController.myCom.decision}" valueChangeListener="#{editCommandController.vclistener}">
<f:selectItems value="#{editCommandController.decisions}" />
<p:ajax />
</p:selectOneMenu>
<p:message for="dec" display="icon" />
<h:outputLabel for="etat" value="Etat : " />
<p:selectOneMenu id="etat" value="#{editCommandController.myCom.etat}" disabled="#{editCommandController.myCom.decision ne 'rejettée'}">
<f:selectItems value="#{editCommandController.etats}" />
</p:selectOneMenu>
<p:message for="etat" display="icon" />
And then in the backing bean add the selectItem if not already present otherwise you can skip it:
public static List<SelectItem> etats = new ArrayList<SelectItem>() { {
add(new SelectItem("Cheese", "Cheese"));
add(new SelectItem("Pickle", "Pickle"));
add(new SelectItem("Mustard", "Mustard"));
add(new SelectItem("Lettuce", "Lettuce"));
}};
public void vclistener(ValueChangeEvent e){
if(e.getNewValue().equals("rejettée")){
EditCommandController.etats.add(0, new SelectItem("Ketchup", "Ketchup"));
myCom.setEtat("Ketchup");
}
RequestContext.getCurrentInstance().update("etat");
}
public List<SelectItem> getEtats() {
return etats;
}
public void setEtats(List<SelectItem> etats) {
EditCommandController.etats = etats;
}

No Update of Fields after Validation error

I have a primefaces dialog in which I can create or update an Employee.
It will open by this
</p:dialog><p:dialog id="employeeEditDialog" header="#{msg.employeeEdit}"
widgetVar="dlgEmployeeEdit" resizable="false">
<p:ajax event="close" listener="#{employeeView.cancel}"
update=":showEmployees:liste" />
<ui:include src="/content/Employee/ShowEmployeeContent.xhtml" />
</p:dialog>
And here is the Dialog Page
<h:form id="editContent">
<p:growl id="growl" showDetail="true" sticky="false" life="5000" />
<p:focus id="focusEdit" for="emSalutation" />
<h:panelGrid columns="2" id="contentGrid">
<h:panelGrid columns="2" id="allgemein"> <h:outputText value="#{msg.id}" />
<h:outputText value="#{employeeView.newEmployee.id}" />
<h:outputText value="#{msg.salutation}" />
<p:selectOneMenu value="#{employeeView.newEmployee.salutation}"
id="emSalutation">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.salutations}" var="salutations"
itemLabel="#{salutations.description}" itemValue="#{salutations}" />
</p:selectOneMenu>
<h:outputText value="#{msg.title}" />
<p:inputText value="#{employeeView.newEmployee.title}" id="emTitle" />
<h:outputText value="#{msg.name}" />
<p:inputText value="#{employeeView.newEmployee.name}" id="emName"
validatorMessage="#{msg.valName}" />
<h:outputText value="#{msg.prename}" />
<p:inputText value="#{employeeView.newEmployee.prename}"
id="emPrename" />
<h:outputText value="#{msg.loginname}" />
<p:inputText value="#{employeeView.newEmployee.loginname}"
validatorMessage="#{msg.valLogin}" />
<h:outputText value="#{msg.department}" />
<h:panelGrid columns="2" id="departmentGrid">
<p:selectOneMenu value="#{employeeView.selectedDepartment.id}"
id="emDepartment">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.departmentList}"
var="department" itemLabel="#{department.description}"
itemValue="#{department.id}" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-disk" immediate="true"
oncomplete="dlgDepartmentAdd.show()"
update="departmentGrid, :departmentAddDialog">
</p:commandButton>
</h:panelGrid>
<h:outputText value="#{msg.position}" />
<h:panelGrid columns="2" id="positionGrid">
<p:selectOneMenu value="#{employeeView.selectedPosition.id}"
id="emPosition">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{employeeView.positionList}" var="position"
itemLabel="#{position.description}" itemValue="#{position.id}" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-disk" immediate="true" id="buttonPos"
oncomplete="dlgPositionAdd.show()"
update="positionGrid, :positionAddDialog">
</p:commandButton>
</h:panelGrid>
<h:outputText value="#{msg.phone}" />
<p:inputText value="#{employeeView.newEmployee.phone}" id="emPhone" />
<h:outputText value="#{msg.fax}" />
<p:inputText value="#{employeeView.newEmployee.fax}" id="emFax" />
<h:outputText value="#{msg.email}" />
<p:inputText value="#{employeeView.newEmployee.email}" id="emEmail"
validator="myEmailValidator" validatorMessage="#{msg.valEmail}" />
<h:outputText value="#{msg.employeedSince}" />
<p:calendar value="#{employeeView.newEmployee.employeedSince}"
id="emEmployeedSince" pattern="dd.MM.yyy" showOn="button" />
<h:outputText value="#{msg.employeedEnd}" />
<p:calendar value="#{employeeView.newEmployee.employeedEnd}"
id="emEmployeedEnd" pattern="dd.MM.yyy" showOn="button" />
<h:outputText value="#{msg.active}" />
<p:selectBooleanCheckbox value="#{employeeView.newEmployee.active}"
id="emActive" />
</h:panelGrid>
</h:panelGrid>
<h:panelGrid columns="3" class="buttonContent" id="button">
<p:commandButton value="#{msg.save}" id="saveButton" update="growl"
oncomplete="if ((!args.validationFailed)) dlgEmployeeEdit.hide()"
actionListener="#{employeeView.saveOrUpdateEmployee}" />
<p:commandButton value="#{msg.cancel}" immediate="true"
oncomplete="dlgEmployeeEdit.hide()"/>
<p:commandButton value="#{msg.delete}" immediate="true"
oncomplete="dlgEmployeeDelete.show()"
disabled="#{(employeeView.newEmployee.id == null) ? true : false}" />
</h:panelGrid>
<p:defaultCommand target="saveButton" /></h:form></html>
And now here are the two Methods which used in the Page:
/**
* Methode zum Speichern und Updaten eines Mitarbeiters
*/
public void saveOrUpdateEmployee() {
FacesContext context = FacesContext.getCurrentInstance();
try {
logger.debug("save aufgerufen " + this.newEmployee);
if (this.selectedDepartment.getId() == null) {
this.newEmployee.setDepartment(null);
}
else {
this.newEmployee.setDepartment(this.departmentHandler.getDepartmentById(this.selectedDepartment.getId()));
}
if (this.selectedPosition.getId() == null) {
this.newEmployee.setPosition(null);
}
else {
this.newEmployee.setPosition(this.positionHandler.getPositionById(this.selectedPosition.getId()));
}
this.employeeController.saveOrUpdate(this.newEmployee);
logger.info("Mitarbeiter erfolgreich gespeichert");
context.addMessage(null, new FacesMessage("Successful", "Mitarbeiter gespeichert "));
}
catch (Exception e) {
logger.error("Fehler beim Speichern des Mitarbeiters", e);
context.addMessage(null, new FacesMessage("Fehler beim Speichern des Mitarbeiters", e.getMessage()));
}
this.loadPersons();
}
/**
* Methode zum Abbrechen bei der Neuanlage/Änderung eines Mitarbeiters
* Felder leeren
*/
public void cancel() {
logger.debug("cancel()");
this.newEmployee = new Employee();
this.selected = new Employee();
this.selectedDepartment = new Department();
this.selectedPosition = new Position();
}
If now, validation failed, the dialog will not hide. This is OK and desired. It shows my created message via FacesMassages as required. If I then close the dialogbox by myself with the "cancel"-Button, dialog will close as expected. In the cancel()-method the object Employee will be set to a new instance of Employee (this.newEmployee = new Employee()) as you can see. But when I open the dialog after validation failure, the object "newEmployee" contains just the old values... Why does my method cancel()not work? I don't understand.
This problem is related to JSF issue 1060 and in detail elaborated in this Q&A: How can I populate a text field using PrimeFaces AJAX after validation errors occur?
To the point, this behaviour is (unfortunately) correct as per current JSF specification and this can be solved as follows: during the invoke action phase you need to collect UIInput components which are included in the ajax render, but not in the ajax execute, and then invoke resetValue() method on them. This can be in a generic and reuseable fashion be done with help of OmniFaces ResetInputAjaxActionListener.

Resources