Table of contents
1.
Introduction
2.
h:message HTML Tag
2.1.
Rendered Output
2.2.
Tag Attributes
3.
Example Application
3.1.
main.xhtml
3.1.1.
Output
4.
Frequently Asked Questions
4.1.
What is meant by JSF?
4.2.
How to display messages in JSF?
4.3.
What is a value-binding expression?
5.
Conclusion
Last Updated: Aug 13, 2025

JSF h:message

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this blog, we will learn about the JSF h:message. JSF (Java Server Faces) is a Java-based web application framework designed to build web-based user interfaces more accessible. The Java Community Process codified a definition for JavaServer Faces, a standardised display technology. The MVC design pattern separates model and display, allowing developers to concentrate on their primary competencies and communicate more effectively. 
The JSF h:message tag displays a message for a particular JSF UI Component. It is used to show a single message for a certain component. By supplying the id of that component into the for property, you may show your message. This article describes the message function in JSF, beginning with the most straightforward statements and progressing to the most significant modules.


 

h:message HTML Tag

<h:inputText  id = "username"  size = "12" label = "UserName" required = "true">
   <f:validateLength for = "username" minimum = "4" maximum = "12" />    
</h:inputText>
<h:message for = "username" style = "color:red" />

 

It is used to show a single message for a certain component. By supplying the id of that component into the for property, you may show your message.

Rendered Output

  • if the supplied username is more than 12 characters.
<span style = "color:red">UserName: Validation Error:
 Length is greater than allowable maximum of '12'</span>

 

  • if the given username has fewer than four characters.
<span style = "color:red">UserName: Validation Error:
    Length is less than allowable minimum of '4'</span>
  • if a username is not provided.
     
<span style = "color:red">UserName: Validation Error:
    Value is required</span>

Tag Attributes

The message Tag properties are listed in the tables below:

S.No.

Attributes

Description

  1.  

title

A title that is used for accessibility. Browsers often generate tooltips for the value of the title.
2.

style

It is used for getting Inline Style Information.
3.

for

It is a required tag that is used to assign the id of the component for which the message is composed.
4.

binding

It obtains a reference to a component that can be utilised in a backing bean.
5.

id

It is used as a Component’s Identifier.
6.

rendered

It is a boolean tag attribute, where false reduces rendering.
7.

styleClass

It is used as the class name for Cascading style sheet(CSS).
8.

errorClass

It adds a CSS style class to any message with the severity class "ERROR".
9.

errorStyle

It styles any message with the severity class "ERROR."
10.

fatalClass

It adds a CSS style class to any message with the severity class "FATAL."
11.

fatalStyle

It styles any message with the severity class "FATAL."
12.

infoClass

It adds a CSS style class to any message with the severity class "INFO."
13.

InfoStyle

It styles any message with the severity class "INFO."
14.

tooltip

It displays the message's detail as a tooltip.
15.

warnClass

It adds a CSS style class to any message with the severity class "WARN."
16.

warnStyle

It styles any message with the severity class "WARN."
17.

showDetail

It is a boolean attribute that specifies whether or not message details are displayed. The defaults for h:message are false and true, respectively.
18.

showSummary

It is a boolean that specifies whether or not message summaries are displayed. The default values are true for h:messages and false for h:message.
19.

layout

Message layout specification: table or list, applied exclusively to h:messages.

 

Example Application

To test the above tag, let's create a test JSF application.

  • As described in the JSF - First Application chapter, create a project called helloworld in the package com.codingNinjas.test.
  • Make the following changes to the main.xhtml: Leave the remainder of the files alone.
  • Compile and run the application to ensure that the business logic works as expected.
  • Finally, create a war file of the application and deploy it to the Apache Tomcat Webserver.
  • In the final step, launch your web application using the right URL.
     

main.xhtml

<!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">
   <head>
      <title>JSF h:message</title>
   </head>
   
   <body>
      <h2>h:messages example</h2>
      <hr />
     
      <h:form>
        <!--Opening the panel grid for dividing the panels-->
         <h:panelGrid id = "panel" columns = "3" border = "0" cellpadding = "10"  
               cellspacing = "1">  
            <h:outputLabel value = "Enter Username" />
            <!--taking the input text-->
            <h:inputText  id = "username"  size = "12" label = "UserName"  
               required = "true">
               <f:validateLength for = "username" minimum = "4" maximum = "12" />    
            </h:inputText>
            <!--Using the h:message tag-->>
            <h:message for = "username" style = "color:red" />
            <h:outputLabel value = "Enter Password" />
           
            <h:inputSecret id = "password" size = "20" label = "Password"  
               required = "true" redisplay = "true" >
               <f:validateLength for = "password" minimum = "5" maximum = "10" />  
            </h:inputSecret>
            <h:message for = "password" style = "color:red" />    
            <h:commandButton id = "submit" value = "Submit" action = "result"/>
         </h:panelGrid>      
      </h:form>
   
   </body>
</html>

Once you have completed all of the changes, compile and run the application as we did in the JSF - First Application chapter. If everything is in order with your application, the following will happen.

Enter any invalid value and then click the Submit button. See the error message below.
 

Output

Frequently Asked Questions

What is meant by JSF?

JSF (Java Server Faces) is a Java-based web application framework designed to make the building of web-based user interfaces easier. The Java Community Process codified a definition for JavaServer Faces, a standardised display technology.

How to display messages in JSF?

The h:messages display all messages, including those already displayed in a page h:message. To display the message on the JSF page, use <h:message for="newPassword1" />.

What is a value-binding expression?

A JavaServer Faces EL expression that refers to a backing bean property. A component tag uses this expression to bind the associated component's value or the component instance to the bean property.

Conclusion

In this blog, we have extensively discussed the JSF h:message. We hope that this article has helped all of you with additional information about Java Server Faces. For more information about Java Server Faces, you can visit Java Frameworks and Introduction to JSP blogs. 
And to learn in-depth about Structure-execution, check out the course on our Ruby on the Coding Ninjas website. For more information about JSF, you can visit JSF-Coding Ninjas and XML-encoding Coding Ninjas blogs. Also, take a look at the Coding Ninjas website for some great information, Web DevelopmentCoding Ninjas Studio ProblemsCoding Ninjas Studio Interview BundleCoding Ninjas Studio Interview ExperiencesCoding Ninjas CoursesCoding Ninjas Studio Contests, and Coding Ninjas Studio Test Series. Do upvote our blog in helping other ninjas grow.

Delighted Programming!

Live masterclass