I need your assistant in updating the <p:message>
component in a JSF page once the non-ajax <p:commandButton>
is clicked. Currently in the case, I need to validate if the employee number is null, then show the error message in the message component, else, nothing to be shown. But now,the form is not showing anything once the <p:commandButton>
is clicked.
Below is the JSF code:
<h:form id="form">
<p:inputText value="#{pdf.refNo}"/>
<p:message id="message" for=":form:cmd2" showDetail="true"/>
<p:commandButton id="cmd2"
value="Validate"
ajax="false"
actionListener="#{pdf.validate}"/>
</h:form>
And the Java bean is:
public void validate() {
if (refNo.equals("") || refNo == null) {
FacesContext.getCurrentInstance().addMessage(":form:cmd2", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Please enter the Employee No."));
}
}
So is the above code is correct and how to show the message once the button is clicked?