I am not able to validate input fields using primefaces ajax on the client side by calling event blur using primefaces
<h:panelGrid columns="2">
<p:outputLabel for="uname" value="Name"/>
<p:inputText id="uname" value="#{userbean.name}" required="true" requiredMessage="Enter your name">
<p:ajax event="blur" rendererType="name"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="name" for="uname" />
<p:outputLabel for="add" value="Address"/>
<p:inputText id="add" value="#{userbean.address}" required="true" requiredMessage="Enter your address">
<p:ajax event="blur" rendered="address"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="address" for="add" />
<h:commandButton value="Submit"/>
</h:panelGrid>
I am not sure what you're doing with 'rendererType and rendered' on your ajax events - they make no sense and ikely just breaking.
I've got it working fine in the below example (note my bean is different name) - i made the grid only 1 in colum size just for testing purposes and you're best off wrapping those full data objects you want re-rendered after ajax request. see the below code p:ajax uses 'update' to render content, where f:ajax uses render="id" etc..
<h:form>
<h:panelGrid columns="1">
<h:panelGroup layout="block" id="nameSection" >
<p:outputLabel for="uname" value="Name"/>
<p:inputText id="uname" value="#{onBlur.name}" required="true" requiredMessage="Enter your name">
<p:ajax event="blur" update="nameSection"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="name" for="uname" />
</h:panelGroup>
<h:panelGroup layout="block" id="addressSection" >
<p:outputLabel for="add" value="Address"/>
<p:inputText id="add" value="#{onBlur.address}" required="true" requiredMessage="Enter your address">
<p:ajax event="blur" update="addressSection"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="address" for="add" />
</h:panelGroup>
</h:panelGrid>
<h:commandButton value="Submit"/>
</h:form>
Related
I have this code, I want to gain advantage of the left space (Not filed value)...
[![<h:panelGrid columns="2" cellpadding="5" >
<p:outputLabel value="Field1:" for="itField1" />
<p:inputText id="itField1" style="width:200px" required="true"
value="#{bean.field1}">
</p:inputText>
<p:outputLabel value="Field2:" for="itField2" />
<h:panelGrid columns="2" style="width:200px" cellpadding="0" cellspacing="0" >
<p:inputText id="itField2" required="true"
value="#{="#{bean.field2}"
/>
<p:commandButton icon="fa fa-search"
/>
</h:panelGrid>
<p:outputLabel value="Field3:" for="itField3" />
<p:inputText id="itField3" style="width:200px" required="true"
value="#{bean.field3}">
</p:inputText>
</h:panelGrid>]
I want this!
But, I get that :( :
How to do it?
This can be achieved by adding CSS style width:100% to <p:inputText id="itField2" ..... /> and <p:commandButton .... />as follows:
<p:inputText id="itField2" value="#{bean.field2}" required="true" style="width:100%" />
<p:commandButton icon="fa fa-search" style="width:100%" />
I have a p:datascroller configured to display a list of entities and lazy loading them upon clicking the more button.
<h:form id="investigationOperationsForm">
<p:dataScroller
value="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations}"
var="investigationOperation" chunkSize="9" lazy="true"
rowIndexVar="test">
<f:facet name="header">
Scroll down to load investigations
</f:facet>
<h:panelGrid columns="2" style="width:100%"
columnClasses="logo,detail">
<p:commandLink oncomplete="PF('investigationDialogW').show()"
update="investigationEditorForm" immediate="true">
<f:setPropertyActionListener value="#{investigationOperation}"
target="#{investigationManagerBackingBean.selection}" />
<p:graphicImage alt="Investigation Operation"
url="/images/common/investigation-operation.png" />
</p:commandLink>
<!-- h:outputText value="#{investigationOperation.name}" /-->
<p:outputPanel id="pnl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="Name:" />
<h:outputText value="#{investigationOperation.name}"
style="font-weight: bold" />
<h:outputText value="Description:" />
<h:outputText value="#{investigationOperation.shortDescription}"
style="font-weight: bold" />
</h:panelGrid>
<p:draggable for="pnl" />
</p:outputPanel>
</h:panelGrid>
<f:facet name="loader">
<p:outputPanel
visible="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations.rowCount gt 10}"
rendered="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations.rowCount gt 10}">
<p:commandLink value="More" />
</p:outputPanel>
</f:facet>
</p:dataScroller>
</h:form>
In addition, I have a dialog that pops up when the p:commandLink oncomplete method is executed where I can update the value of the current selection and persist the changes.
<p:dialog id="investigationDialog"
header="#{msg['inv-manager.invDialog.header.title']}"
widgetVar="investigationDialogW" minWidth="400" minHeight="400"
resizable="false" position="center center" modal="true">
<p:panel id="investigationEditorPanel">
<h:form id="investigationEditorForm">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="name"
value="#{msg['inv-manager.invDialog.nameFieldLabel']}" />
<p:inplace id="nameInplaceEditor" editor="true">
<p:inputText
value="#{investigationManagerBackingBean.selection.name}"
id="name" required="true" immediate="true"
label="#{msg['inv-manager.invDialog.nameFieldInputLabel']}" />
</p:inplace>
<h:outputLabel for="shortDescription"
value="#{msg['inv-manager.invDialog.shortDescriptionFieldLabel']}" />
<p:inplace id="shortDescriptionInplaceEditor" editor="true">
<p:inputText
value="#{investigationManagerBackingBean.selection.shortDescription}"
id="shortDescription" required="true" immediate="true"
label="#{msg['inv-manager.invDialog.shortDescriptionFieldInputLabel']}" />
</p:inplace>
<h:outputLabel for="description"
value="#{msg['inv-manager.invDialog.descriptionFieldLabel']}" />
<p:inputTextarea id="description" required="false"
label="#{msg['inv-manager.invDialog.descriptionFieldInputLabel']}"
immediate="true"
value="#{investigationManagerBackingBean.selection.description}" />
<p:commandButton id="okButton"
value="#{msg['inv-manager.invDialog.okButton']}" type="submit"
partialSubmit="true" process="investigationEditorForm"
action="#{investigationManagerBackingBean.createOrUpdate()}"
onclick="dlg.hide();" />
</h:panelGrid>
</h:form>
</p:panel>
</p:dialog>
The backing bean is configured to be #ViewScoped and everything works as defined. However, upon update the values of the p:datascroller are reset and the load method of the lazy loading model is executed and the datascroller is repopulated with new values from the database.
I have no reference to the datascroller or its containing form in the p:dialog and am wondering why the datascroller is being updated automagically? What am I missing in the equation. Have I overlooked something or something specific to the p:datascroller model that I need to consider when following this approach?
Look forward to the expertise of the community in resolving this issue.
Many thanks in advance :)
I have a Form to add a new user. I am using Validator messages to control empty fields. If I enter invalid data and submit the form, error messages were displayed. After that I click on reset button, it doesn't work.
This my code in html:
<h:form id="newCustomerForm">
<p:dialog draggable="true" header="New Customer" widgetVar="customerDialogNew" resizable="false"
showEffect="clip" hideEffect="fold" style="position: absolute ;" id="dialog2">
<p:panelGrid id="newCustomer" columns="6" >
<f:facet name="header">
<p:graphicImage value="../../pictures/customerAdd.jpg"/>
</f:facet>
<p:outputLabel value="Name:" for="name" />
<p:inputText id="name" value="#{customerMB.name}" title="Name" required="true" requiredMessage="The Name field is required."/>
<p:message for="name" />
<p:outputLabel value="FamilyName:" for="familyName" />
<p:inputText id="familyName" value="#{customerMB.familyName}" title="FamilyName" required="true" requiredMessage="The FamilyName field is required."/>
<p:message for="familyName" />
</p:panelGrid>
<p:commandButton type="reset" immediate="true" update="newCustomerForm" value="Clear" icon="ui-icon-arrowrefresh-1-n" styleClass="ui-priority-primary">
</p:commandButton>
<p:commandButton value="Save" ajax="false" icon="ui-icon-circle-check" styleClass="ui-priority-primary" action="#{customerMB.addCustomer()}" />
</p:dialog>
</h:form>
How can I show all validation messages in one pop up using growl, because by default every validation message on the client side creates new pop up.
Of course I could do validation on the server side and send final message to the growl but is it possible to do it on the client side?
Some code goes here:
<p:dialog id="chPwD" header="#{res['user.passwordDialogHeader']}" widgetVar="changePwV" closeOnEscape="true" resizable="false">
<p:growl id="growl" showDetail="false" life="3000" />
<h:panelGrid id="chPwPG" columns="1" cellpadding="1" transient="true">
<h:panelGrid id="chPwPGi" columns="2" cellpadding="1">
<p:outputLabel for="pwd0" value="#{res['user.oldPassword']}" />
<h:panelGroup>
<p:password id="pwd0" label="#{res['user.oldPassword']}" value="#{mngr.oldPassword}" required="true" style="width:250px;"/>
<span style="display:inline-block;"><p:message for="pwd0"/><p:messages for="pwd0"/></span>
</h:panelGroup>
<p:outputLabel for="pwd1" value="#{res['user.newPassword']}" />
<h:panelGroup>
<p:password id="pwd1" label="#{res['user.newPassword']}" value="#{mngr.newPassword}" match="pwd2" required="true" style="width:250px;"/>
<span style="display:inline-block;"><p:message for="pwd1"/></span>
</h:panelGroup>
<p:outputLabel for="pwd2" value="#{res['user.repeatNewPassword']}" />
<h:panelGroup>
<p:password id="pwd2" label="#{res['user.repeatNewPassword']}" value="#{mngr.newPassword}" required="true" style="width:250px;"/>
<span style="display:inline-block;"><p:message for="pwd2"/></span>
</h:panelGroup>
</h:panelGrid>
</h:panelGrid>
<f:facet name="footer">
<p:commandButton value="#{res['btn.apply']}" style="margin-right:20px;" update=":chPwPG" action="#{mngr.changeSelectedUserPassword}" oncomplete="handlePwChangeRequest(xhr, status, args)"/>
<p:commandButton value="#{res['btn.cancel']}" onclick="changePwV.hide();" type="button"/>
</f:facet>
</p:dialog>
you should try <p:messages showDetail="false" showSummary="true"/> and it work for me.
Updating the question to below:
Please see attached code.
<h:form id="tblForm" styleClass="formTblClass">
<h3 style="text-align: center; background-color: purple; color: white;">Contact Details</h3>
<h:panelGrid id="contactPanel" columns="3">
<h:outputLabel for="roleIn" value="Role: " />
<h:selectOneMenu id="roleIn" value="#{docHeader.roleIn}" required="true" requiredMessage="Please select one from dropdown.">
<f:selectItem itemLabel="--Select--" noSelectionOption="true"/>
<f:selectItems value="#{docHeader.listOfRoles}"/>
</h:selectOneMenu>
<h:message for="roleIn" style="color: red;"/>
<h:outputLabel for="empIdIn" value="Employee ID: " />
<h:inputText id="empIdIn" value="#{docHeader.empId}" required="true" requiredMessage="Please enter valid employee id">
<f:ajax listener="#{docHeader.fetchEmpDetails}" render="empName workPhone emailId" />
</h:inputText>
<h:message for="empIdIn" style="color: red;"/>
<h:outputLabel for="empName" value="Name: " />
<h:inputText id="empName" readonly="true" value="#{docHeader.empName}" /><br/>
<h:outputLabel for="workPhone" value="Work Phone: " />
<h:inputText id="workPhone" readonly="true" value="#{docHeader.workPhone}" /><br/>
<h:outputLabel for="emailId" value="Email ID: " />
<h:inputText id="emailId" readonly="true" value="#{docHeader.emailId}" /><br/>
</h:panelGrid>
<h:commandButton value="Add">
<f:ajax event="click" listener="#{docHeader.addContactToList}"
render="contactPanel contactTable" execute="#this contactPanel" />
</h:commandButton>
<h:dataTable id="contactTable" value="#{docHeader.contactList}"
var="contact" headerClass="list-header" rowClasses="list-row" columnClasses="list-column-center" border="1" width="100%">
<h:column>
<f:facet name="header">Role</f:facet>#{contact.roleIn}
</h:column>
<h:column>
<f:facet name="header">Employee ID</f:facet>#{contact.empId}
</h:column>
<h:column>
<f:facet name="header">Employee Name</f:facet>#{contact.empName}
</h:column>
<h:column>
<f:facet name="header">Work Phone</f:facet>#{contact.workPhone}
</h:column>
<h:column>
<f:facet name="header">Email ID</f:facet>#{contact.emailId}
</h:column>
</h:dataTable>
<div style="text-align: center">
<h:commandButton value="Next">
<f:ajax event="click" render="none" listener=""/>
</h:commandButton>
</div>
</h:form>
From above code, addtoContactList is working absolutely fine and the contactTable is displaying the information too.
But when clicked on NEXT i'm getting required field messages and not able to navigate to the next page.
When clicked next i want execute a method in managed bean like moveToNextPage.
Any Ideas appreciated.
You have <h:message> tag for each inputText in the upper panelGrid. So by default <f:ajax> does the following render="#this" and execute="#this". You need to change like below:
<h:panelGrid id="myPanel" columns="3">
<h:outputLabel for="wrNum" value="ITG/WR #: " />
<h:inputText id="wrNum" required="true" value="#{docHeader.wrNum}" requiredMessage="Please enter ITG/WR #."/>
<h:message for="wrNum"/>
<h:outputLabel for="wrDesc" value="ITG/WR Description: " />
<h:inputText id="wrDesc" required="true" value="#{docHeader.wrDesc}" requiredMessage="Please enter ITG/WR Description"/>
<h:message for="wrDesc"/>
</h:panelGrid>
<h:commandButton value="Add" immediate="true">
<f:ajax event="click" listener="#{docHeader.addWrReqInfoToList}" render="myPanel workReqInfoTbl" execute="#this myPanel"/>
</h:commandButton>
<h:dataTable id="workReqInfoTbl" value="#{docHeader.workReqInfoList}" var="wrReqInfo" style="border: red solid 1px;">
</h:dataTable>