|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.struts2.components.Component
public class Component
Base class to extend for UI components.
This class is a good extension point when building reuseable UI components.
Field Summary | |
---|---|
protected ActionMapper |
actionMapper
|
static String |
COMPONENT_STACK
|
protected Map |
parameters
|
protected ValueStack |
stack
|
protected boolean |
throwExceptionOnELFailure
|
Constructor Summary | |
---|---|
Component(ValueStack stack)
Constructor. |
Method Summary | |
---|---|
void |
addAllParameters(Map params)
Adds all the given parameters to this component's own parameters. |
void |
addParameter(String key,
Object value)
Adds the given key and value to this component's own parameter. |
boolean |
altSyntax()
Is the altSyntax enabled? [TRUE] See struts.properties where the altSyntax flag is defined. |
static boolean |
altSyntax(ValueStack stack)
Is the altSyntax enabled? [TRUE] |
protected String |
completeExpressionIfAltSyntax(String expr)
Adds the sorrounding %{ } to the expression for proper processing. |
void |
copyParams(Map params)
Pushes this component's parameter Map as well as the component itself on to the stack and then copies the supplied parameters over. |
protected String |
determineActionURL(String action,
String namespace,
String method,
HttpServletRequest req,
HttpServletResponse res,
Map parameters,
String scheme,
boolean includeContext,
boolean encodeResult,
boolean forceAddSchemeHostAndPort,
boolean escapeAmp)
Renders an action URL by consulting the ActionMapper . |
protected String |
determineNamespace(String namespace,
ValueStack stack,
HttpServletRequest req)
Determines the namespace of the current page being renderdd. |
boolean |
end(Writer writer,
String body)
Callback for the end tag of this component. |
protected boolean |
end(Writer writer,
String body,
boolean popComponentStack)
Callback for the start tag of this component. |
protected StrutsException |
fieldError(String field,
String errorMsg,
Exception e)
Constructs a RuntimeException based on the given information. |
protected Component |
findAncestor(Class clazz)
Finds the nearest ancestor of this component stack. |
protected String |
findString(String expr)
Evaluates the OGNL stack to find a String value. |
protected String |
findString(String expr,
String field,
String errorMsg)
Evaluates the OGNL stack to find a String value. |
protected String |
findStringIfAltSyntax(String expr)
This check is needed for backwards compatibility with 2.1.x |
protected Object |
findValue(String expr)
Finds a value from the OGNL stack based on the given expression. |
protected Object |
findValue(String expr,
Class toType)
Evaluates the OGNL stack to find an Object of the given type. |
protected Object |
findValue(String expr,
String field,
String errorMsg)
Evaluates the OGNL stack to find an Object value. |
private String |
getComponentName()
Gets the name of this component. |
Stack |
getComponentStack()
Gets the component stack of this component. |
Map |
getParameters()
Gets the parameters. |
ValueStack |
getStack()
Gets the OGNL value stack assoicated with this component. |
protected void |
popComponentStack()
Pops the component stack. |
void |
setActionMapper(ActionMapper mapper)
|
void |
setThrowExceptionsOnELFailure(String throwException)
|
boolean |
start(Writer writer)
Callback for the start tag of this component. |
protected String |
stripExpressionIfAltSyntax(String expr)
If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off. |
static String |
stripExpressionIfAltSyntax(ValueStack stack,
String expr)
If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off. |
protected String |
toString(Throwable t)
Constructs a string representation of the given exception. |
boolean |
usesBody()
Overwrite to set if body shold be used. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String COMPONENT_STACK
protected ValueStack stack
protected Map parameters
protected ActionMapper actionMapper
protected boolean throwExceptionOnELFailure
Constructor Detail |
---|
public Component(ValueStack stack)
stack
- OGNL value stack.Method Detail |
---|
private String getComponentName()
public void setActionMapper(ActionMapper mapper)
public void setThrowExceptionsOnELFailure(String throwException)
public ValueStack getStack()
public Stack getComponentStack()
public boolean start(Writer writer)
writer
- the output writer.
public boolean end(Writer writer, String body)
writer
- the output writer.body
- the rendered body.
protected boolean end(Writer writer, String body, boolean popComponentStack)
writer
- the output writer.body
- the rendered body.popComponentStack
- should the component stack be popped?
protected void popComponentStack()
protected Component findAncestor(Class clazz)
clazz
- the class to look for, or if assignable from.
protected String findString(String expr)
expr
- OGNL expression.
protected String findString(String expr, String field, String errorMsg)
RuntimeException
is thrown
constructed with a messaged based on the given field and errorMsg paramter.
expr
- OGNL expression.field
- field name used when throwing RuntimeException
.errorMsg
- error message used when throwing RuntimeException
.
StrutsException
- is thrown in case of expression is null.protected StrutsException fieldError(String field, String errorMsg, Exception e)
RuntimeException
based on the given information.
A message is constructed and logged at ERROR level before being returned
as a RuntimeException
.
field
- field name used when throwing RuntimeException
.errorMsg
- error message used when throwing RuntimeException
.e
- the caused exception, can be null.
StrutsException
.protected Object findValue(String expr)
expr
against stack except when expr
is null. If altsyntax (%{...}) is applied, simply strip it off.
expr
- the expression. Returns null if expr is null.
protected String stripExpressionIfAltSyntax(String expr)
expr
- the expression (must be not null)
public static String stripExpressionIfAltSyntax(ValueStack stack, String expr)
stack
- the ValueStack where the context value is searched for.expr
- the expression (must be not null)
public static boolean altSyntax(ValueStack stack)
stack
- the ValueStack where the context value is searched for.
struts.properties
where the altSyntax flag is defined.public boolean altSyntax()
struts.properties
where the altSyntax flag is defined.
protected String completeExpressionIfAltSyntax(String expr)
expr
- the expression.
protected String findStringIfAltSyntax(String expr)
expr
- the expression.
protected Object findValue(String expr, String field, String errorMsg)
findValue(String)
except that if the
given expression is null a error is logged and
a RuntimeException
is thrown constructed with a
messaged based on the given field and errorMsg paramter.
expr
- OGNL expression.field
- field name used when throwing RuntimeException
.errorMsg
- error message used when throwing RuntimeException
.
StrutsException
- is thrown in case of not found in the OGNL stack, or expression is null.protected Object findValue(String expr, Class toType)
expr
the portion wrapped with altSyntax (%{...})
against stack when altSyntax is on, else the whole expr
is evaluated against the stack.
This method only supports the altSyntax. So this should be set to true.
expr
- OGNL expression.toType
- the type expected to find.
protected String determineActionURL(String action, String namespace, String method, HttpServletRequest req, HttpServletResponse res, Map parameters, String scheme, boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp)
ActionMapper
.
action
- the actionnamespace
- the namespacemethod
- the methodreq
- HTTP requestres
- HTTP responseparameters
- parametersscheme
- http or httpsincludeContext
- should the context path be included or notencodeResult
- should the url be encodedforceAddSchemeHostAndPort
- should the scheme host and port be forcedescapeAmp
- should ampersand (&) be escaped to &
protected String determineNamespace(String namespace, ValueStack stack, HttpServletRequest req)
namespace
- the namespacestack
- OGNL value stackreq
- HTTP request
public void copyParams(Map params)
params
- the parameters to copy.protected String toString(Throwable t)
t
- the exception
public Map getParameters()
public void addAllParameters(Map params)
params
- the parameters to add.public void addParameter(String key, Object value)
key
- the key of the new parameter to add.value
- the value assoicated with the key.public boolean usesBody()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |