<h:panelGrid id="details" columns="2" columnClasses="formColumn1,formColumn2">
<pe:requiredLabel for="firstName" value="First Name: "/>
<p:inputText id="firstName" required="true" title="#{component.valid ? '' : 'First Name can not be empty'}"/>
<pe:requiredLabel for="lastName" value="Last Name: "/>
<p:inputText id="lastName" required="true" title="#{component.valid ? '' : 'Last Name can not be empty'}"/>
</h:panelGrid>
<p:commandButton value="Submit" process="details" update="details" style="margin-top: 10px;"/>
<pe:tooltip global="true" position="left center" targetPosition="right center" forSelector=".ui-state-error"/>
In this case if i need to handle error other validations like minimum length , datatype of field then how can i handle it ?
ToolTips for error on validation
With attached validators
myBean.errorMessage should return last added (by any validator(s)) error message(s) which you can get in your bean as
Look in PF's MessageRenderer.java for more information.
Code: Select all
<p:inputText id="lastName" required="true" title="#{component.valid ? '' : myBean.errorMessage}">
<f:validateABC ..../>
<f:validateXYZ ..../>
</p:inputText>
Code: Select all
Iterator<FacesMessage> msgs = facesContext.getMessages("lastName");
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
No. You can use quite normally validators. In case of validation error, component set to invalid and the message is added to FacesContext as FacesMessage. You should try to get the added message in the bean.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
The bean is called when you update (render) input fields. If validation failed, the rendering phase is called. Input fields will be re-rendered in any case. As I said you can access messages in FacesContext from your bean. Maybe sogar in facelets direct (not tried)
Look into MessageRenderer.java as I said. You can copy code from there. Where is the problem?
Code: Select all
title="#{component.valid ? '' : facesContext.getMessages('lastName').next().getDetail()}"
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
I tried it special for you. It works. Here is the code:
XHTML
Java (controller bean)
The same is for all fields and validators. You can also customize default message text in JSF validators. Standard JSF validators store messages under well-defined keys. Refer JSF docu please how to do this.
XHTML
Code: Select all
<p:inputText id="lastName" required="true" label="Last Name" title="#{component.valid ? '' : myController.messageForLastName}"/>
Code: Select all
public String getMessageForLastName() {
return FacesContext.getCurrentInstance().getMessages("lastName").next().getDetail();
}
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
More generic and better if you use EL 2.x
I added this tip to my blog post http://ovaraksin.blogspot.de/2012/03/sh ... -with.html
Code: Select all
<p:inputText id="lastName" required="true" label="Last Name" title="#{component.valid ? '' : myController.getErrorMessage(component.clientId)}"/>
Code: Select all
public String getErrorMessage(final String clientId) {
Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages(clientId);
if (iter.hasNext()) {
return iter.next().getDetail(); // or getSummary()
}
return "";
}
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin
-
- Information
-
Who is online
Users browsing this forum: No registered users and 18 guests