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.
- Since:
- 3.1
- Author:
- Bauke Scholtz
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisResolverForKeyword(SearchExpressionContext context, String keyword) Returnstruewhen keyword equals "messages".static voidregister(Application application) Invoked byApplicationProcessor.voidresolve(SearchKeywordContext context, UIComponent component, String keyword) Grab the currentUIForm, visit it and collect client IDs of allUIMessageandUIMessagescomponents and finally invoke context call back with anUIMessagecomponent whose client ID returns a space separated collection of found client IDs.Methods inherited from class jakarta.faces.component.search.SearchKeywordResolver
isLeaf, isPassthrough
-
Constructor Details
-
MessagesKeywordResolver
public MessagesKeywordResolver()
-
-
Method Details
-
register
Invoked byApplicationProcessor.- Parameters:
application- Involved faces application.
-
isResolverForKeyword
Returnstruewhen keyword equals "messages".- Specified by:
isResolverForKeywordin classSearchKeywordResolver
-
resolve
Grab the currentUIForm, visit it and collect client IDs of allUIMessageandUIMessagescomponents and finally invoke context call back with anUIMessagecomponent whose client ID returns a space separated collection of found client IDs.- Specified by:
resolvein classSearchKeywordResolver
-