Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <h:messages> do in JSF?

Tags:

jsf

message

I am learning JSF and came across this line:

<h:messages layout="table"></h:messages>

in a sample application ?

Am not sure what does this line do? I get no error when removing the line from the code, and am able to run it and get the same output ?

like image 798
bibek Avatar asked Mar 22 '10 10:03

bibek


1 Answers

The h:messages tag renders all messages for the current JSF view which are not covered by a h:message (remark the missing 's' at the end) tag. Messages can be generated explicitly by your backing beans (FacesContext.addMessage) or implicitly by JSF.

E.g. if you have marked an input value as required and the user submits the form without filling in the required value, an error message will be added to the view. If a h:message tag is bound to the relevant component, the message will be rendered there, otherwise it will be rendered by the global h:messages tag in your view (if any).

The layout attribute specifies what the HTML code to be generated should look like. The table layout (used in your example) uses an HTML table to display messages, while the list layout uses a bulleted list (HTML ul tag).

If you do not specify a h:messages tag in your view and also no h:message tags, the user will not be informed about errors. Therefore, it is best practice to include a h:message tag for each input component of your view and a h:messages tag for your whole view to ensure that all messages are visible to the user.

You will find a compact JSF tag reference at JSF Toolbox.

like image 170
sven Avatar answered Sep 29 '22 09:09

sven