FetchBeanInfos (<b:fetchBeanInfos />)

<b:fetchBeanInfos> is a non-visual component. Its purpose is to make information about the server available to JavaScript.

<b:fetchBeanInfos> sets the global JavaScript variable validationFailed after processing a JSF event. If one of the validation constraints is violated, validationFailed is set to true, otherwise it's false.

It also sets five global JavaScript variables, allowing you to determine which was the highest severity level, and which severity classes of messages have been generated during the last validation.

Basic usage

A typical use case is to prevent modal dialogs from closing or opening until the input is valid. In this example, the <b:commandButton /> page uses <b:fetchBeanInfos /> to open a modal dialog only if every validation constraint is fulfilled:

Caveat

Please not that validationFailed indicates that the validation phase of the JSF lifecycle has reported an error. It does not indicate that there's an error message. If you add error messages in an action or actionListener, better check bfHasError || bfHasFatalError to get reliable results.

Advanced usage

<b:fetchBeanInfos /> populates six global JavaScript variables:

validationFailed
is true if one of the JSF validators found an error during the validation phase of the JSF lifecycle
bfMaximumMessageSeverity
ordinal number of the most disturbing FacesMessage. 0=no message, 1=info, 2=warning, 3=error, 4=fatal error.
bfHasFatalError
Is there at least one fatal error message?
bfHasError
Is there at least one error message?
bfHasWarning
Is there at least one warning message?
bfHasInfo
Is there at least one info message?

You can see these variable in the example below. For technical reasons, the values of the variables are shown in an alert box. Click the button to see it.

By the way, the example also shows the effect of the validation phase of JSF. If you clear the first checkbox, the messages below disappear. That's because the uppermost error is detected by a bean validation constraint. The other messages are generated during the INVOKE_APPLICATION phase of the lifecycle. However, the application is never invoked as long as JSF detects contraint violations.

AJAX

If you're using AJAX, don't forget to include the <b:fetchBeanInfos> widget in the list of updated regions.