I have a JSF 2.1 + PrimeFaces 3.3 page:
<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>
I'm trying to manually add faces messages when the name is invalid:
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"));
}
}
But they do not show up and the server log keeps printing the following warning:
There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered
How do I show them in the page?
And, a second question, if I submit the form with three empty input fields, it shows "required input error message" in each <p:message>
associated with the <p:inputText>
. How do I show them in the <p:message globalOnly="true">
?