Reputation: 475
I am working on a form, where i am using primefaces. When i validate an inputtext, then ajax message is working for only for field and not for the others, please, check my code below.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h2>h:validateLength Example</h2>
<h:form>
<p:panel id="panel" header="New User">
<label for="name" >Name*</label>
<p:inputText id="name" value="#{userData.name}"
label="name" >
<f:validateLength minimum="7" />
<p:ajax execute="currentInput" update="msgLastname" event="blur" process="@this"/>
<p:message for="name" id = "msgLastname" display="icon" style="color:red" />
</p:inputText>
<p:inputText id="lastname" value="#{userData.lastname}">
<f:validateLength minimum="5"/>
<p:ajax execute="currentInput" update="msg" event="blur" process="@this"/>
<p:message for="lastname" id="msg" display="icon"/>
</p:inputText>
<p:commandButton value="submit" action="result" />
</p:panel>
</h:form>
</h:body>
</html>
Upvotes: 0
Views: 3095
Reputation: 522719
You need to move the <p:message>
tags outside of the <p:inputText>
tags like this:
<p:inputText id="name" value="#{userData.name}" label="name" >
<f:validateLength minimum="7" />
<p:ajax execute="currentInput" update="msgLastname" event="blur" process="@this"/>
</p:inputText>
<p:message for="name" id="msgLastname" display="icon" style="color:red" />
<p:inputText id="lastname" value="#{userData.lastname}">
<f:validateLength minimum="5"/>
<p:ajax execute="currentInput" update="msg" event="blur" process="@this"/>
</p:inputText>
<p:message for="lastname" id="msg" display="icon"/>
If you want to show both the text and the icon in the validation message, then remove the display="icon"
parameter, e.g.:
<p:message for="name" id="msgLastname" style="color:red" />
Upvotes: 1