我正在使用表格,我正在使用primefaces。当我验证输入文本时,ajax消息仅适用于字段而不适用于其他字段,请检查下面的代码。
<?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>
答案 0 :(得分:1)
您需要移动<p:message>
代码中的<p:inputText>
代码 ,如下所示:
<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"/>
如果要在验证消息中同时显示文本和图标,请删除display="icon"
参数,例如:
<p:message for="name" id="msgLastname" style="color:red" />