In this section we will explain you JSF message tag. This is used to display the most recent message for the component. This is used to show the message for a particular component. This tag shows the message for the component specified in for attribute of message tag. If you want to customize the message then CSS can be used. If you want to show the error message for a component in a color and other information in different color then CSS can be helpful.
Code Description :
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <f:view> <html> <body> <h:form>Enter text in this box :<br> <h:inputText id="input_text" value="#{MessageBean.a}" required="true"/> <h:message for="input_text" /><br> <h:commandButton action="Submit" value="Submit"/> </h:form> </body> </html> </f:view> |
Rendered Output :

If this input text field is not filled by the user and submit is pressed then the error message is flashed for this component to warn that this is the required field to be filled. It shows that it can't be left blank because "required" field is set to "true" for the input field. The message tag shows the error message related to this component because its "for" attribute is set to the id for this input text field. So if this field is left blank before submitting the page, then the output comes as below :

Html Source Code :
|
This tag has some attributes that can be used for different purpose. These attributes are described below :
|
Recommend the tutorial |
Ask Questions? Discuss: JSF message Tag View All Comments
Post your Comment