- MessagesKeywordResolver
Available since OmniFaces 3.1
The @messages
search keyword resolver will automatically resolve all UIMessage
and UIMessages
components within the current UIForm
. This is particularly useful when you have a relatively large form and would like to Ajax-update only the message components when submitting the form.
<h:form id="form">
<h:inputText id="input1" ... />
<h:message id="m_input1" for="input1" />
<h:inputText id="input2" ... />
<h:message id="m_input2" for="input2" />
<h:inputText id="input3" ... />
<h:message id="m_input3" for="input3" />
...
<h:commandButton ...>
<f:ajax execute="@form" render="@messages" />
</h:commandButton>
<h:messages id="m_form" globalOnly="true" redisplay="false" />
</h:form>
This has only one prerequirement: the message component must have a fixed id
attribute set as demonstrated above. Otherwise Faces won't render anything to the client side when there are no messages and ultimately JavaScript won't be able to find it when processing the Faces Ajax response.
This keyword resolver is already registered by OmniFaces own faces-config.xml
and thus gets auto-initialized when the OmniFaces JAR is bundled in a web application, so end-users do not need to register this keyword resolver explicitly themselves.
Compatibility
This keyword resolver is only compatible with <f:ajax>
of Mojarra 2.3.4 or newer. This keyword resolver is not compatible with <p:ajax>
of PrimeFaces 6.x. It's only compatible with a PrimeFaces version designed specifically for JSF 2.3.
<h:form id="form">
<h3>All these inputs are required</h3>
<h:panelGrid columns="2">
<h:inputText id="input1" required="true" />
<h:message id="m_input1" for="input1" />
<h:inputText id="input2" required="true" />
<h:message id="m_input2" for="input2" />
<h:inputText id="input3" required="true" />
<h:message id="m_input3" for="input3" />
<h:commandButton value="submit">
<f:ajax execute="@form" render="@messages" />
</h:commandButton>
</h:panelGrid>
<h:messages id="m_form" globalOnly="true" redisplay="false" />
</h:form>