Package org.apache.struts2.components
Class Component
java.lang.Object
org.apache.struts2.components.Component
- Direct Known Subclasses:
- ContextBean,- Else,- ElseIf,- I18n,- If,- Include,- OptGroup,- Param,- Property,- Push,- UIBean
Base class to extend for UI components.
 
This class is a good extension point when building reusable UI components.
This class is a good extension point when building reusable UI components.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ActionMapperstatic final Stringprotected booleanprotected booleanprotected booleanprotected ValueStackprotected static ConcurrentMap<Class<?>,Collection<String>> Caches information about common tag's attributes to reduce scanning for annotation @StrutsTagAttributeprotected boolean
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAllAttributes(Map<String, Object> additionalAttributes) Adds all the given attributes to this component's own attributes.voidaddParameter(String key, Object value) Adds the given key and value to this component's own parameter.protected StringcompleteExpression(String expr) Adds the surrounding %{ } to the expression for proper processing.voidcopyAttributes(Map<String, Object> attributesToCopy) Pushes this component's parameter Map as well as the component itself on to the stack and then copies the supplied parameters over.protected StringdetermineActionURL(String action, String namespace, String method, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, Map<String, Object> parameters, String scheme, boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp) Renders an action URL by consulting theActionMapper.protected StringdetermineNamespace(String namespace, ValueStack stack, jakarta.servlet.http.HttpServletRequest req) Determines the namespace of the current page being renderdd.booleanCallback for the end tag of this component.protected booleanCallback for the start tag of this component.booleanOverride to set if body content should be HTML-escaped.protected StrutsExceptionfieldError(String field, String errorMsg, Exception e) Constructs aRuntimeExceptionbased on the given information.protected ComponentfindAncestor(Class<?> clazz) Finds the nearest ancestor of this component stack.protected StringfindString(String expr) Evaluates the OGNL stack to find a String value.protected StringfindString(String expr, String field, String errorMsg) Evaluates the OGNL stack to find a String value.protected ObjectFinds a value from the OGNL stack based on the given expression.protected ObjectEvaluates the OGNL stack to find an Object of the given type.protected ObjectEvaluates the OGNL stack to find an Object value.Gets the attributes.Gets the component stack of this component.protected StringgetNamespace(ValueStack stack) booleangetStack()Gets the OGNL value stack associated with this component.protected Collection<String>If needed caches all methods annotated by given annotation to avoid further scansprotected booleanisAcceptableExpression(String expression) Checks if expression doesn't contain vulnerable codebooleanisValidTagAttribute(String attrName) Checks if provided name is a valid tag's attributeprotected voidPops the component stack.voidsetActionMapper(ActionMapper mapper) voidsetDevMode(String devMode) voidsetEscapeHtmlBody(String escapeHtmlBody) voidsetNotExcludedAcceptedPatterns(NotExcludedAcceptedPatternsChecker notExcludedAcceptedPatterns) voidsetPerformClearTagStateForTagPoolingServers(boolean performClearTagStateForTagPoolingServers) Request that the tag state be cleared duringStrutsBodyTagSupport.doEndTag()processing, which may help with certain edge cases with tag logic running on servers that implement JSP Tag Pooling.voidsetThrowExceptionsOnELFailure(String throwException) voidsetUrlHelper(UrlHelper urlHelper) booleanCallback for the start tag of this component.protected StringstripExpression(String expression) If %{...} is applied, simply strip the "%{" and "}" off.protected StringConstructs a string representation of the given exception.booleanusesBody()Overwrite to set if body should be used.
- 
Field Details- 
COMPONENT_STACK- See Also:
 
- 
standardAttributesMapCaches information about common tag's attributes to reduce scanning for annotation @StrutsTagAttribute
- 
devModeprotected boolean devMode
- 
escapeHtmlBodyprotected boolean escapeHtmlBody
- 
stack
- 
attributes
- 
actionMapper
- 
throwExceptionOnELFailureprotected boolean throwExceptionOnELFailure
- 
performClearTagStateForTagPoolingServersprotected boolean performClearTagStateForTagPoolingServers
 
- 
- 
Constructor Details- 
ComponentConstructor.- Parameters:
- stack- OGNL value stack.
 
 
- 
- 
Method Details- 
setDevMode
- 
setActionMapper
- 
setThrowExceptionsOnELFailure
- 
setEscapeHtmlBody
- 
setUrlHelper
- 
setNotExcludedAcceptedPatternspublic void setNotExcludedAcceptedPatterns(NotExcludedAcceptedPatternsChecker notExcludedAcceptedPatterns) 
- 
getStackGets the OGNL value stack associated with this component.- Returns:
- the OGNL value stack associated with this component.
 
- 
getComponentStackGets the component stack of this component.- Returns:
- the component stack of this component, never null.
 
- 
startCallback for the start tag of this component. Should the body be evaluated?- Parameters:
- writer- the output writer.
- Returns:
- true if the body should be evaluated
 
- 
endCallback for the end tag of this component. Should the body be evaluated again?
 NOTE: will pop component stack.- Parameters:
- writer- the output writer.
- body- the rendered body.
- Returns:
- true if the body should be evaluated again
 
- 
endCallback for the start tag of this component. Should the body be evaluated again?
 NOTE: has a parameter to determine to pop the component stack.- Parameters:
- writer- the output writer.
- body- the rendered body.
- popComponentStack- should the component stack be popped?
- Returns:
- true if the body should be evaluated again
 
- 
popComponentStackprotected void popComponentStack()Pops the component stack.
- 
findAncestorFinds the nearest ancestor of this component stack.- Parameters:
- clazz- the class to look for, or if assignable from.
- Returns:
- the component if found, null if not.
 
- 
findStringEvaluates the OGNL stack to find a String value.- Parameters:
- expr- OGNL expression.
- Returns:
- the String value found.
 
- 
findStringEvaluates the OGNL stack to find a String value.
 If the given expression is null a error is logged and aRuntimeExceptionis thrown constructed with a messaged based on the given field and errorMsg parameter.- Parameters:
- expr- OGNL expression.
- field- field name used when throwing- RuntimeException.
- errorMsg- error message used when throwing- RuntimeException.
- Returns:
- the String value found.
- Throws:
- StrutsException- is thrown in case of expression is null.
 
- 
fieldErrorConstructs aRuntimeExceptionbased on the given information.
 A message is constructed and logged at ERROR level before being returned as aRuntimeException.- Parameters:
- field- field name used when throwing- RuntimeException.
- errorMsg- error message used when throwing- RuntimeException.
- e- the caused exception, can be null.
- Returns:
- the constructed StrutsException.
 
- 
findValueFinds a value from the OGNL stack based on the given expression. Will always evaluateexpragainst stack except whenexpris null. If %{...} is applied, simply strip it off.- Parameters:
- expression- the expression. Returns null if expr is null.
- Returns:
- the value, null if not found.
 
- 
stripExpressionIf %{...} is applied, simply strip the "%{" and "}" off.- Parameters:
- expression- the expression (must be not null)
- Returns:
- the stripped expression
 
- 
completeExpressionAdds the surrounding %{ } to the expression for proper processing.- Parameters:
- expr- the expression.
- Returns:
- the modified expression wrapped with %{...}
 
- 
findValueEvaluates the OGNL stack to find an Object value. Function just like findValue(String)except that if the given expression is null a error is logged and aRuntimeExceptionis thrown constructed with a messaged based on the given field and errorMsg parameter.- Parameters:
- expr- OGNL expression.
- field- field name used when throwing- RuntimeException.
- errorMsg- error message used when throwing- RuntimeException.
- Returns:
- the Object found, is never null.
- Throws:
- StrutsException- is thrown in case of not found in the OGNL stack, or expression is null.
 
- 
findValueEvaluates the OGNL stack to find an Object of the given type. Will evaluateexpressionthe portion wrapped with %{...} against stack if evaluating to String.class, else the wholeexpressionis evaluated against the stack.- Parameters:
- expression- OGNL expression.
- toType- the type expected to find.
- Returns:
- the Object found, or null if not found.
 
- 
determineActionURLprotected String determineActionURL(String action, String namespace, String method, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, Map<String, Object> parameters, String scheme, boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp) Renders an action URL by consulting theActionMapper.- Parameters:
- action- the action
- namespace- the namespace
- method- the method
- req- HTTP request
- res- HTTP response
- parameters- parameters
- scheme- http or https
- includeContext- should the context path be included or not
- encodeResult- should the url be encoded
- forceAddSchemeHostAndPort- should the scheme host and port be forced
- escapeAmp- should ampersand (&) be escaped to &
- Returns:
- the action url.
 
- 
determineNamespaceprotected String determineNamespace(String namespace, ValueStack stack, jakarta.servlet.http.HttpServletRequest req) Determines the namespace of the current page being renderdd. Useful for Form, URL, and href generations.- Parameters:
- namespace- the namespace
- stack- OGNL value stack
- req- HTTP request
- Returns:
- the namepsace of the current page being rendered, is never null.
 
- 
getNamespace
- 
copyAttributesPushes this component's parameter Map as well as the component itself on to the stack and then copies the supplied parameters over. Because the component's parameter Map is pushed before the component itself, any key-value pair that can't be assigned to component will be set in the parameters Map.- Parameters:
- attributesToCopy- the attributes to copy.
 
- 
toStringConstructs a string representation of the given exception.- Parameters:
- t- the exception
- Returns:
- the exception as a string.
 
- 
getAttributesGets the attributes.- Returns:
- the attributes. It's never null.
 
- 
addAllAttributesAdds all the given attributes to this component's own attributes.- Parameters:
- additionalAttributes- the attributes to add.
 
- 
addParameterAdds the given key and value to this component's own parameter.
 If the provided key is null nothing happens. If the provided value is null any existing parameter with the given key name is removed.- Parameters:
- key- the key of the new parameter to add.
- value- the value associated with the key.
 
- 
usesBodypublic boolean usesBody()Overwrite to set if body should be used.- Returns:
- always false for this component.
 
- 
escapeHtmlBodypublic boolean escapeHtmlBody()Override to set if body content should be HTML-escaped.- Returns:
- always true (default) for this component.
- Since:
- 6.0.0
 
- 
isValidTagAttributeChecks if provided name is a valid tag's attribute- Parameters:
- attrName- String name of attribute
- Returns:
- true if attribute with the same name was already defined
 
- 
getStandardAttributesIf needed caches all methods annotated by given annotation to avoid further scans- Returns:
- list of attributes
 
- 
setPerformClearTagStateForTagPoolingServerspublic void setPerformClearTagStateForTagPoolingServers(boolean performClearTagStateForTagPoolingServers) Request that the tag state be cleared duringStrutsBodyTagSupport.doEndTag()processing, which may help with certain edge cases with tag logic running on servers that implement JSP Tag Pooling. Note: All Tag classes that extendStrutsBodyTagSupportmust implement a setter for this attribute (same name), and it must be defined at the Tag class level. Defining a setter in the superclass alone is insufficient (results in "Cannot find a setter method for the attribute").- Parameters:
- performClearTagStateForTagPoolingServers- true if tag state should be cleared, false otherwise.
 
- 
getPerformClearTagStateForTagPoolingServerspublic boolean getPerformClearTagStateForTagPoolingServers()
- 
isAcceptableExpressionChecks if expression doesn't contain vulnerable code- Parameters:
- expression- of the component
- Returns:
- true|false
- Since:
- 6.0.0
 
 
-