BootsFaces offers a short-hand API to report FacesMessages
:
You can assign a FacesMessage
to a particular field by providing its id. Alternatively,
you can use a search expression describing one or more fields. This comes in handy because the Java
backend shouldn't know much about the implementation details of the front-end, at least not if you're
following a paradigm like MVC, MVP or MVVM. A fairly common solution is to add a semantic CSS class
to the input field (i.e. a CSS class that doesn't modify the look and feel, but serves as a marker).
Another, probably even better approach is to use the EL expression of the input field, because the
EL expression reflects the server-side data structure. We'll come back to the corresponding search expression
@property(.)
in a minute.
The search expressions use the root of the JSF tree as base component. If your JSF tree contains a lot of
components, this may result in slow evaluation of the search expressions scanning the entire subtree, such as
@styleClass
, **:id
, @findIdRecursively
and @findPartialIdRecursively
.
You can improve performance by limiting the search scope. For instance, if you know the field you want to
decorate with an error message is in a form with a particular id, you can speed things up like so:
The search expression @property
allows you to use the variable name to define the FacesMessage
.
More precicly, @property
find the JSF component by its EL expression (without the curly braces):