我有一个 JSF 2.1 + PrimeFaces 3.3 页面:
<h:form id="particluar">
<p:message id="msg" globalOnly="true" display="text"/>
<h:panelGrid columns="2" id="test">
<h:panelGrid id="panel2" columns="3">
<p:inputText id="name1" value="Student.studentID" required="true"/>
<p:commandButton value="Check Name" actionListener="#{Student.abc}" process="name1" update="panel2" />
<p:message id="msg1" for="name1" display="text"/>
</h:panelGrid>
<p:inputText id="name2" required="true"/>
<p:message id="msg2" for="name2" display="text"/>
<p:inputText id="name3" required="true"/>
<p:message id="msg3" for="name3" display="text"/>
</h:panelGrid>
<p:commandButton value="submit" actionListener="#{Student.xyz}" update="particluar" />
</h:form>
当名称无效时,我正在尝试手动添加面孔消息:
public void xyz() {
if (name1.equals("primefaces")) {
FacesContext.getCurrentInstance().addMessage("msg1", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
}
if (name2.equals("primefaces")) {
FacesContext.getCurrentInstance().addMessage("msg2", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
}
if (name3.equals("primefaces")) {
FacesContext.getCurrentInstance().addMessage("msg3", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid Name", "Invalid Name"));
}
}
但是它们没有出现,并且服务器日志不断打印以下警告:
有一些未处理的 FacesMessage,这意味着不是每个 FacesMessage 都有机会被渲染
如何在页面中显示它们?
而且,第二个问题,如果我提交带有三个空输入字段的表单,它会在每个<p:message>
与<p:inputText>
. 如何在 中显示它们<p:message globalOnly="true">
?