Class MessagesKeywordResolver
- java.lang.Object
-
- jakarta.faces.component.search.SearchKeywordResolver
-
- org.omnifaces.component.search.MessagesKeywordResolver
-
public class MessagesKeywordResolver extends SearchKeywordResolver
The
@messages
search keyword resolver will automatically resolve allUIMessage
andUIMessages
components within the currentUIForm
. 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 Constructor Description MessagesKeywordResolver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isResolverForKeyword(SearchExpressionContext context, String keyword)
Returnstrue
when keyword equals "messages".static void
register(Application application)
Invoked byApplicationProcessor
.void
resolve(SearchKeywordContext context, UIComponent component, String keyword)
Grab the currentUIForm
, visit it and collect client IDs of allUIMessage
andUIMessages
components and finally invoke context call back with anUIMessage
component whose client ID returns a space separated collection of found client IDs.-
Methods inherited from class jakarta.faces.component.search.SearchKeywordResolver
isLeaf, isPassthrough
-
-
-
-
Method Detail
-
register
public static void register(Application application)
Invoked byApplicationProcessor
.- Parameters:
application
- Involved faces application.
-
isResolverForKeyword
public boolean isResolverForKeyword(SearchExpressionContext context, String keyword)
Returnstrue
when keyword equals "messages".- Specified by:
isResolverForKeyword
in classSearchKeywordResolver
-
resolve
public void resolve(SearchKeywordContext context, UIComponent component, String keyword)
Grab the currentUIForm
, visit it and collect client IDs of allUIMessage
andUIMessages
components and finally invoke context call back with anUIMessage
component whose client ID returns a space separated collection of found client IDs.- Specified by:
resolve
in classSearchKeywordResolver
-
-