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 ?
The
h:messagestag renders all messages for the current JSF view which are not covered by ah: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:messagetag is bound to the relevant component, the message will be rendered there, otherwise it will be rendered by the globalh:messagestag in your view (if any).The
layoutattribute specifies what the HTML code to be generated should look like. Thetablelayout (used in your example) uses an HTML table to display messages, while thelistlayout uses a bulleted list (HTMLultag).If you do not specify a
h:messagestag in your view and also noh:messagetags, the user will not be informed about errors. Therefore, it is best practice to include ah:messagetag for each input component of your view and ah:messagestag 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.