Wednesday, January 09, 2013

JSF 2.x Tip of the Day: Displaying Content Conditionally by FacesMessage.Severity

Many times we do, or do not want to display content based on whether there are FacesMessage queued to be displayed. The FacesMessage.Severity can be used to help us determine if messages should be displayed. Please see the table below.

FacesMessage Values
Ordinal Severity
0 INFO
1 WARN
2 ERROR
3 FATAL


The examples below demonstrate a couple of techniques to determine if a component (in this case a <ui:fragment/> containing a <ui:include/>) should be displayed based on whether FacesMessage.Severity are present and if they are not equal to an informational message.

This is equivalent to the listing above.
This displays if the messages are WARN or less.

2 comments :

Unknown said...

Something that's maybe worth mentioning is that while the fragment will be rendered conditionally based on the error level, the include will take place no matter what. So don't put huge pieces of code in those included pages, and also keep in mind that whatever is in those pages could be resolved, which can lead to errors.

John Yeary said...

The will not be placed included in the page. The will determine whether the included page will be rendered. I rechecked it in a simple test to ensure that it would not render.

Did I miss the point?

You are correct that you will want to be careful about any conditionally rendered pages, and included pages.

The size issue may, or may not be an issue. The will need to be processed and having a lot of them conditionally rendered especially in a , or can cause performance issues.

Thanks for your input.

Popular Posts