public class MessagesKeywordResolver extends SearchKeywordResolver
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
JSF 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 JSF 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.
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.
Constructor and Description |
---|
MessagesKeywordResolver() |
Modifier and Type | Method and Description |
---|---|
boolean |
isResolverForKeyword(SearchExpressionContext context,
String keyword)
Returns
true when keyword equals "messages". |
static void |
register(Application application)
Invoked by
ApplicationProcessor . |
void |
resolve(SearchKeywordContext context,
UIComponent component,
String keyword)
Grab the current
UIForm , visit it and collect client IDs of all UIMessage and UIMessages components and
finally invoke context call back with an UIMessage component whose client ID returns a space separated collection of found
client IDs. |
isLeaf, isPassthrough
public static void register(Application application)
ApplicationProcessor
.application
- Involved faces application.public boolean isResolverForKeyword(SearchExpressionContext context, String keyword)
true
when keyword equals "messages".isResolverForKeyword
in class SearchKeywordResolver
public void resolve(SearchKeywordContext context, UIComponent component, String keyword)
UIForm
, visit it and collect client IDs of all UIMessage
and UIMessages
components and
finally invoke context call back with an UIMessage
component whose client ID returns a space separated collection of found
client IDs.resolve
in class SearchKeywordResolver
Copyright © 2012–2022 OmniFaces. All rights reserved.