Class SearchExpressionHandler
- java.lang.Object
-
- jakarta.faces.component.search.SearchExpressionHandler
-
- Direct Known Subclasses:
SearchExpressionHandlerWrapper
public abstract class SearchExpressionHandler extends Object
The SearchExpressionHandler is responsible for resolving search expression(s)A search expression consists of either an identifier (which is matched exactly against the
idproperty of aUIComponent, or a keyword (like@thisor@form), or a series of such identifiers and keywords linked by theUINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)character value. SeeSearchKeywordResolverfor the list of supported keywords. The search algorithm must operate as follows, though alternate alogrithms may be used as long as the end result is the same:- Identify the
UIComponentthat will be the base for searching:- If the search expression begins with the separator character (called an "absolute" search expression), the base
will be the
UIViewRoot. The leading separator character will be stripped off, and the remainder of the search expression will be treated as a "relative" search expression as described below. - Otherwise, the
SearchExpressionContext.getSource()will be used.
- If the search expression begins with the separator character (called an "absolute" search expression), the base
will be the
- The search expression (possibly modified in the previous step) is now a "relative" search expression that will be
used to locate the component (if any) based on the identifier and/or keywords:
- The expression will be splitted by
UINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)into "commands". The commands will be resolved one by one. For the first command, the source component, like mentioned above, will be used to start the lookup. For all further commands, the previous resolved component, from the previous command, will be used the start the lookup. - If the command starts with the
KEYWORD_PREFIX, then it is considered as a keyword and theSearchKeywordResolvers will be used the resolve the keyword. - Otherwise, if the command does not start with
KEYWORD_PREFIX, then the component will be resolved based on the component ID.
- The expression will be splitted by
- Since:
- 2.3
-
-
Field Summary
Fields Modifier and Type Field Description protected static char[]EXPRESSION_SEPARATOR_CHARSThe default characters used to separate expressions in a series of expressions.static StringKEYWORD_PREFIXThe prefix to identify a keyword.
-
Constructor Summary
Constructors Constructor Description SearchExpressionHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description char[]getExpressionSeperatorChars(FacesContext context)Return the characters used to separate expressions in a series of expressions.abstract voidinvokeOnComponent(SearchExpressionContext searchExpressionContext, UIComponent previous, String expression, ContextCallback callback)Resolves multipleUIComponents for the given expression.voidinvokeOnComponent(SearchExpressionContext searchExpressionContext, String expression, ContextCallback callback)Resolves multipleUIComponents for the given expression.abstract booleanisPassthroughExpression(SearchExpressionContext searchExpressionContext, String expression)Checks if the given expression is a "passtrough expression".abstract booleanisValidExpression(SearchExpressionContext searchExpressionContext, String expression)Checks if the given expression is a valid expression.abstract StringresolveClientId(SearchExpressionContext searchExpressionContext, String expression)Resolves to a single clientId or passthrough expression for the given expression.abstract List<String>resolveClientIds(SearchExpressionContext searchExpressionContext, String expressions)Resolves to aListwith clientIds or passthrough expressions for the given expressions.abstract voidresolveComponent(SearchExpressionContext searchExpressionContext, String expression, ContextCallback callback)Resolves a singleUIComponents for the given expression.abstract voidresolveComponents(SearchExpressionContext searchExpressionContext, String expressions, ContextCallback callback)Resolves multipleUIComponents for the given expression(s).abstract String[]splitExpressions(FacesContext context, String expressions)Splits an string, based ongetExpressionSeperatorChars(jakarta.faces.context.FacesContext)with possible multiple expressions into an array.
-
-
-
Field Detail
-
KEYWORD_PREFIX
public static final String KEYWORD_PREFIX
The prefix to identify a keyword.
- Since:
- 2.3
- See Also:
- Constant Field Values
-
EXPRESSION_SEPARATOR_CHARS
protected static final char[] EXPRESSION_SEPARATOR_CHARS
The default characters used to separate expressions in a series of expressions. Expressions are per default separated by space and comma.
- Since:
- 2.3
-
-
Method Detail
-
resolveClientId
public abstract String resolveClientId(SearchExpressionContext searchExpressionContext, String expression)
Resolves to a single clientId or passthrough expression for the given expression.
- Parameters:
searchExpressionContext- theSearchExpressionContextexpression- the search expression- Returns:
- The resolved clientId or passtrough expression. If the expression can not be resolved and if
SearchExpressionHint.IGNORE_NO_RESULTwas passed,nullwill be returned. - Throws:
ComponentNotFoundException- if the expression can not be resolved and ifSearchExpressionHint.IGNORE_NO_RESULTwas not passed.FacesException- if the expression is not valid.- Since:
- 2.3
-
resolveClientIds
public abstract List<String> resolveClientIds(SearchExpressionContext searchExpressionContext, String expressions)
Resolves to a
Listwith clientIds or passthrough expressions for the given expressions. The expressions will be splitted bysplitExpressions(jakarta.faces.context.FacesContext, java.lang.String)and resolved one by one.- Parameters:
searchExpressionContext- theSearchExpressionContextexpressions- the search expressions- Returns:
- The resolved clientIds and passtrough expressions.
- Throws:
ComponentNotFoundException- if one of the expression can not be resolved and ifSearchExpressionHint.IGNORE_NO_RESULTwas not passed.FacesException- if the expression is not valid.- Since:
- 2.3
-
resolveComponent
public abstract void resolveComponent(SearchExpressionContext searchExpressionContext, String expression, ContextCallback callback)
Resolves a single
UIComponents for the given expression. If the component is resolved, theContextCallbackwill be invoked.- Parameters:
searchExpressionContext- theSearchExpressionContextexpression- the search expressioncallback- the callback for the resolved component- Throws:
ComponentNotFoundException- if the expression can not be resolved and ifSearchExpressionHint.IGNORE_NO_RESULTwas not passed.FacesException- if the expression is not valid.- Since:
- 2.3
-
resolveComponents
public abstract void resolveComponents(SearchExpressionContext searchExpressionContext, String expressions, ContextCallback callback)
Resolves multiple
UIComponents for the given expression(s). The expressions will be splitted bysplitExpressions(jakarta.faces.context.FacesContext, java.lang.String)and resolved one by one. For each resolved component, theContextCallbackwill be invoked.- Parameters:
searchExpressionContext- theSearchExpressionContextexpressions- the search expression(s)callback- the callback for each resolved component- Throws:
ComponentNotFoundException- if any of the expressions can not be resolved and ifSearchExpressionHint.IGNORE_NO_RESULTwas not passed.FacesException- if the expression is not valid.- Since:
- 2.3
-
invokeOnComponent
public void invokeOnComponent(SearchExpressionContext searchExpressionContext, String expression, ContextCallback callback)
Resolves multiple
UIComponents for the given expression. For each resolved component, theContextCallbackwill be invoked. This method is the most essential method in the API. It implements the algorithm which handles the recursion of the keywords and id's.- Parameters:
searchExpressionContext- theSearchExpressionContextexpression- the search expressioncallback- the callback for the resolved component- Throws:
FacesException- if the expression is not valid.- Since:
- 2.3
-
invokeOnComponent
public abstract void invokeOnComponent(SearchExpressionContext searchExpressionContext, UIComponent previous, String expression, ContextCallback callback)
Resolves multiple
UIComponents for the given expression. For each resolved component, theContextCallbackwill be invoked. This method is the most essential method in the API. It implements the algorithm which handles the recursion of the keywords and id's.- Parameters:
searchExpressionContext- theSearchExpressionContextprevious- The previous resolved component, that will be the base for searchingexpression- the search expressioncallback- the callback for the resolved component- Throws:
FacesException- if the expression is not valid.- Since:
- 2.3
-
splitExpressions
public abstract String[] splitExpressions(FacesContext context, String expressions)
Splits an string, based on
getExpressionSeperatorChars(jakarta.faces.context.FacesContext)with possible multiple expressions into an array.- Parameters:
context- theFacesContextfor the current requestexpressions- The expressions as string- Returns:
- the expression(s) as array
- Since:
- 2.3
-
isPassthroughExpression
public abstract boolean isPassthroughExpression(SearchExpressionContext searchExpressionContext, String expression)
Checks if the given expression is a "passtrough expression". A passthrough expression must only be a keyword. This keyword will not be resolved by the
SearchKeywordResolverand will be returned untouched. The client is responsible to resolve it later.- Parameters:
searchExpressionContext- theSearchExpressionContextexpression- the expression- Returns:
- If the given expression is a passtrough expression
- Since:
- 2.3
-
isValidExpression
public abstract boolean isValidExpression(SearchExpressionContext searchExpressionContext, String expression)
Checks if the given expression is a valid expression.
A expression is invalid if:- No
SearchKeywordResolvermatches the requested keyword - A keyword or id is placed after a leaf keyword (@none:@form)
- Parameters:
searchExpressionContext- theSearchExpressionContextexpression- the expression- Returns:
- If the given expression is a valid expression
- Since:
- 2.3
- No
-
getExpressionSeperatorChars
public char[] getExpressionSeperatorChars(FacesContext context)
Return the characters used to separate expressions in a series of expressions. The default implementation returns
EXPRESSION_SEPARATOR_CHARS.- Parameters:
context- theFacesContextfor the current request- Returns:
- the separator chars
- Since:
- 2.3
-
-