JSF Primefaces input values reset upon SelectOnemenu - ajax

The entered input values reset upon manually selecting the values of selectOneMenu id="format"
The render of selectOneMenu id="format" works fine. But upon selection of the drop down values of selectOneMenu id="format" the entered field input values are blank.
Page
Employee name[Mark] Employee Type [New]
Format [Select some drop down value]
.
Current Output
Employee name[Entered Value Disappeared/null] Employee Type [Selected value disappeared/null]
Format [Selected some drop down value]
Expected Output
Employee name[Mark] Employee Type [New]
Format [Selected Value]
.
I have tried to add
<p:ajax event="valueChange" immediate="true" process="#form" />
The rendering fails if I add it for the selectOneMenu
I have the code below
main.xhtml
<h:form id="newFormBank" enctype="multipart/form-data">
<h:panelGroup id="id">
<p:growl id="growl" sticky="true" showDetail="true" />
<p:wizard id="newBankWizard" showNavBar="true" widgetVar="bankWiz" flowListener="#{javaMB.wizardFlow}">
<p:tab id="pro" title="Banks">
<ui:include src="/jsf/xyz.xhtml" />
<ui:include src="/jsf/employeeloan.xhtml" />
</p:tab>
</p:wizard>
</h:panelGroup>
</h:form>
employeeloan.xhtml
<p:panel id="employeeLoan" styleClass="panelNoBorder">
<div class="ui-g"> <div class="ui-g-1"><p:outputLabel value="Employee Name" /></div>
<div class="ui-g-3"> <p:row> <p:inputText id="employeeName" maxlength="50" style="width: 65%;" value="#{javaMB.visaDetailsEntity.employeeName}" > </p:inputText> </p:row> </div>
<div class="ui-g-1"><p:outputLabel value="Employee Type" /></div>
<div class="ui-g-3">
<p:row> <p:selectOneMenu id="employeeTypeList" value="#{javaMB.visaDetailsEntity.employeeTypeCode}" >
<f:selectItem itemLabel="Select Release Type" itemValue=""> </f:selectItem>
<f:selectItem itemLabel="New" itemValue="1" />
<f:selectItem itemLabel="Existing" itemValue="2" /> </p:selectOneMenu> </p:row> </div> </div>
<div class="ui-g"> <div class="ui-g-1"><p:outputLabel value="CREDIT" /></div>
<div class="ui-g-3">
<p:row>
<p:selectOneMenu id="format" value="javaMB.visaDetailsEntity.visaType.visaId">
<f:selectItem itemLabel="VISA" itemValue="1" />
<f:selectItem itemLabel="MASTER CARD" itemValue="2" />
<f:selectItem itemLabel="DISCOVER" itemValue="3" />
<f:selectItem itemLabel="AMERICAN EXPRESS" itemValue="4" />
<f:ajax render="#form" />
</p:selectOneMenu>
</p:row>
</div>
</div>
<div class="ui-g">
<div class="ui-g-1"><p:outputLabel value="VISA" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '1'}"/></div>
<div class="ui-g-3"> <p:row>
<p:inputText id="visaeg" maxlength="9" size="30" value="#{javaMB.visaDetailsEntity.malaustin}" label="VISA1" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '1'}">
</p:inputText>
</p:row>
</div>
<div class="ui-g-1"><p:outputLabel value="VISA" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '1'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="visaegg" maxlength="11" size="30" value="#{javaMB.visaDetailsEntity.malecinyc}" label="VISA2" onchange="negateLongitude()" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '1'}">
</p:inputText>
</p:row>
</div>
</div>
<div class="ui-g">
<div class="ui-g-1"><h:outputLabel value="MASTER CARD" style="overflow: hidden" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '3'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="masterd" maxlength="7" size="30" value="#{javaMB.visaDetailsEntity.atepmo}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '3'}">
</p:inputText>
</p:row>
</div>
<div class="ui-g-1"><h:outputLabel for="masterdt" value="MASTER CARD DETAILS" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '3'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="datilsmast" maxlength="8" size="30" value="#{javaMB.visaDetailsEntity.atepllanyc}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '3'}">
</p:inputText>
</p:row>
</div>
</div>
<div class="ui-g">
<div class="ui-g-1"><h:outputLabel value="DISCOVER" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '4'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="ltdiscover" maxlength="2" size="30" value="#{javaMB.visaDetailsEntity.egrssfo}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '4'}">
</p:inputText>
</p:row>
</div>
<div class="ui-g-1"><h:outputLabel value="DISCOVER Details" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '4'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="lodiscover" maxlength="4" size="30" value="#{javaMB.visaDetailsEntity.eongtx}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '4'}">
</p:inputText>
</p:row>
</div>
</div>
<div class="ui-g">
<div class="ui-g-1"><h:outputLabel value="AExp AZ" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '2'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="azaexp" maxlength="2" size="30" value="#{javaMB.visaDetailsEntity.aexpaz}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '2'}">
</p:inputText>
</p:row>
</div>
<div class="ui-g-1"><h:outputLabel value="AExp FL" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '2'}"/></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="flaexp" maxlength="4" size="30" value="#{fvLocationMB.coordinateForm.aexpazfl}" rendered="#{javaMB.visaDetailsEntity.visaType.visaId == '2'}">
</p:inputText>
</p:row>
</div>
</div>
</div>
</p:fieldset>
</p:panel>
</ui:composition>
javaMB
getters setters
Entity
getters setters

Your p:ajax statement is wrong, it should probably read something like:
<p:ajax event="valueChange" update="#form" />
Find an exhaustive explanation of the inner workings here:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes

Related

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".

PrimeFaces CommandButton does not Update

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>

f:ajax not rendering h:selectManyListbox

Using f:ajax component with h:selectManyListbox, it is firing the listener method but not refreshing the rendering list.
I have Market. When I select market it needs to display Sub-Markets. Initial page load will have all the Markets and Sub-Markets, but it needs to filter when user selects "Market".
Using below code:
<ui:fragment id="uda2" rendered="#{udaList.index eq 1}">
<div class=" row form-group" >
<label class="col-sm-2" for="sel-service">Market:</label>
<div class="col-sm-10">
<h:selectManyListbox style="width:360px;" multiple="" pt:aria-required="true" required="required" pt:data-toggle="chosen"
disabled="# {licenseSelectionBean.isFieldEnabled(FormFieldsEnum.ITEM_UDA2)}"
id="#{FormFieldsEnum.ITEM_UDA2.getFieldCode()}" size="1"
name="#{FormFieldsEnum.ITEM_UDA2.getFieldCode()}"
value="#{licenseSelectionBean.selectedItemUda2}"
styleClass="sel-chosen">
<f:selectItems var="uda2"
value="#{licenseSelectionBean.selectUda2}" />
<f:ajax event="change" execute="#this" render="#this udalist3"
listener="#{licenseSelectionBean.onChangeFilter()}" />
</h:selectManyListbox>
</div>
</div>
</ui:fragment>
<ui:fragment rendered="#{udaList.index eq 2}">
<div class="row form-group" >
<label class="col-sm-2" for="sel-service">Sub-Market:</label>
<div class="col-sm-10">
<h:selectManyListbox style="width:360px;" multiple="" pt:aria-required="true" required="required" pt:data-toggle="chosen"
disabled="#{licenseSelectionBean.isFieldEnabled(FormFieldsEnum.ITEM_UDA3)}"
size="1"
pt:name="udalist3"
value="#{licenseSelectionBean.selectedItemUda3}"
pt:id="udalist3"
styleClass="sel-chosen">
<f:selectItems var="uda3"
value="#{licenseSelectionBean.selectUda3}" />
<!-- <f:ajax render="#{FormFieldsEnum.ITEM_UDA4.getFieldCode()}"
listener="#{licenseSelectionBean.onChangeFilter()}" /> -->
</h:selectManyListbox>
</div>
</div>
</ui:fragment>
Used "pt" for pass-through because JSF prefixing dynamic id.
How to resolve this problem?
Simple solution. Replace
<f:ajax event="change" execute="#this" render="#this udalist3"
listener="#{licenseSelectionBean.onChangeFilter()}" />
with
<f:ajax event="change" execute="#this" render="#form"
listener="#{licenseSelectionBean.onChangeFilter()}" />
This might cause some unnecesarry traffic. You can also encapsulate the second ui:fragment in a panelgroup, e.g.
<h:panelGroup id="wrapper">
<ui:fragment rendered="#{udaList.index eq 2}">
....
</h:panelgroup>
and add replace "udalist3" with "wrapper" in the f:ajax render attribute.

jsf messages enqueued and not display

I have a jsf Form with fields, submit and messages for it
<h:form id="loginForm">
<h:outputText value="Введите логин и пароль:"/>
<h:panelGrid columns="2">
<h:outputLabel for="email" value="E-Mail:"/>
<h:inputText id="email" value="#{sign.email}" required="true" requiredMessage="Введите e-mail" validatorMessage="email должен быть вида abc#abc.abc">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</h:inputText>
<h:outputLabel for="password" value="Password:"/>
<h:inputSecret converter="pwdConverter" id="password" value="#{sign.password}" required="true" requiredMessage="Введите пароль"/>
<h:commandButton action="#{sign.doLogin()}" value="Войти"/>
<h:commandLink action="/pages/register?faces-redirect=true" immediate="true" value="Зарегистрироваться"/>
</h:panelGrid>
<h:messages for="loginForm"/>
</h:form>
And it works fine: when I just click on the submit without input anything, it shows me a validation erros, but when I added a facebook-login button, I have a message in server log: Info: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=loginForm:email[severity=(ERROR 2), summary=(Введите e-mail), detail=(Введите e-mail)] for each field and validation messages not displayed on the page any more
there is how I added a fb-button:
<h:outputScript library="js" name="login.js"/>
<h:form id="loginForm">
<h:outputText value="Введите логин и пароль:"/>
<h:panelGrid columns="2">
<h:outputLabel for="email" value="E-Mail:"/>
<h:inputText id="email" value="#{sign.email}" required="true" requiredMessage="Введите e-mail" validatorMessage="email должен быть вида abc#abc.abc">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]#[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</h:inputText>
<h:outputLabel for="password" value="Password:"/>
<h:inputSecret converter="pwdConverter" id="password" value="#{sign.password}" required="true" requiredMessage="Введите пароль"/>
<h:commandButton action="#{sign.doLogin()}" value="Войти"/>
<h:commandLink action="/pages/register?faces-redirect=true" immediate="true" value="Зарегистрироваться"/>
</h:panelGrid>
<h:messages for="loginForm"/>
</h:form>
<br/>
<div class="fb-login-button" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="true"></div>
<div id="status"/>

Submit button doesn't work correctly with ajax jsf 2.0 onblur validation

I'm trying to implement ajax client side validation with jsf 2.0 (primefaces).
I prefer onblur event rather than ontype, because it seems more user friendly. The problem is: my Register button has to be clicked twice to work correctly when a focus is inside an invalid field. 1st time we click - onblur event happens, 2nd time we click - submit happens (i suggest this is the reason). My code:
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="template.xhtml">
<ui:define name="content">
<p:panel header="#{msg['register']}" style="width: 550px; align: left;">
<h:form>
<h:panelGrid columns="3" cellpadding="2">
<h:outputLabel for="name" value="#{msg['yourName']}:" />
<p:inputText id="name" value="#{userManagedBean.name}">
<f:validateLength maximum="20" />
<p:ajax update="msgName" event="blur" />
</p:inputText>
<p:message for="name" id="msgName" display="text"/>
<h:outputLabel for="userName" value="*#{msg['login']}:"/>
<p:inputText id="userName" value="#{userManagedBean.username}" label="UserName" required="true">
<f:validateLength minimum="5" maximum="20" for="userName"/>
<p:ajax update="msgUserName" event="blur"/>
</p:inputText>
<p:message for="userName" id="msgUserName"/>
<h:outputLabel for="password" value="*#{msg['password']}:" />
<p:password id="password" value="#{userManagedBean.password}" required="true">
<f:validator validatorId="confirmPasswordValidator" />
<f:attribute name="confirm" value="#{confirmPassword.submittedValue}" />
<f:ajax event="blur" execute="password confirm" render="m_password" />
</p:password>
<p:message id="m_password" for="password" />
<h:outputLabel for="confirm" value="*#{msg['retypePassword']}:" />
<p:password id="confirm" binding="#{confirmPassword}" required="true">
<f:ajax event="blur" execute="password confirm" render="m_password m_confirm" />
</p:password>
<p:message id="m_confirm" for="confirm" />
<h:outputLabel for="email" value="#{msg['email']}:"/>
<p:inputText id="email" value="#{userManagedBean.email}" label="email">
<f:validateRegex pattern="^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" for="email"/>
<p:ajax update="msgEmail" event="blur"/>
</p:inputText>
<p:message for="email" id="msgEmail"/>
</h:panelGrid>
<ui:remove><p:captcha label="Captcha"/> </ui:remove>
<h:commandButton type="submit" value="#{msg['register']}" action="#{userManagedBean.register}"></h:commandButton>
</h:form>
</p:panel>
</ui:define>
</ui:composition>
</html>

Resources