Methods Summary |
---|
public void | addAllParameters(java.util.Map params)Add's all the given parameters to this componenets own parameters.
parameters.putAll(params);
|
public void | addParameter(java.lang.String key, java.lang.Object value)Add's the given key and value to this components own parameter.
If the provided key is null nothing happends.
If the provided value is null any existing parameter with
the given key name is removed.
if (key != null) {
Map params = getParameters();
if (value == null) {
params.remove(key);
} else {
params.put(key, value);
}
}
|
public boolean | altSyntax()Is the altSyntax enabled? [TRUE]
See struts.properties where the altSyntax flag is defined.
return ContextUtil.isUseAltSyntax(stack.getContext());
|
public void | copyParams(java.util.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. Because the component's parameter Map is
pushed before the component itself, any key-value pair that can't be assigned to componet
will be set in the parameters Map.
stack.push(parameters);
stack.push(this);
try {
for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String key = (String) entry.getKey();
stack.setValue(key, entry.getValue());
}
} finally {
stack.pop();
stack.pop();
}
|
protected java.lang.String | determineActionURL(java.lang.String action, java.lang.String namespace, java.lang.String method, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.util.Map parameters, java.lang.String scheme, boolean includeContext, boolean encodeResult)Renders an action URL by consulting the {@link org.apache.struts2.dispatcher.mapper.ActionMapper}.
String finalAction = findString(action);
String finalNamespace = determineNamespace(namespace, getStack(), req);
ActionMapping mapping = new ActionMapping(finalAction, finalNamespace, method, parameters);
String uri = actionMapper.getUriFromActionMapping(mapping);
return UrlHelper.buildUrl(uri, req, res, parameters, scheme, includeContext, encodeResult);
|
protected java.lang.String | determineNamespace(java.lang.String namespace, com.opensymphony.xwork2.util.ValueStack stack, javax.servlet.http.HttpServletRequest req)Determines the namespace of the current page being renderdd. Useful for Form, URL, and href generations.
String result;
if (namespace == null) {
result = TagUtils.buildNamespace(actionMapper, stack, req);
} else {
result = findString(namespace);
}
if (result == null) {
result = "";
}
return result;
|
public boolean | end(java.io.Writer writer, java.lang.String body)Callback for the end tag of this component.
Should the body be evaluated again?
NOTE: will pop component stack.
return end(writer, body, true);
|
protected boolean | end(java.io.Writer writer, java.lang.String body, boolean popComponentStack)Callback for the start tag of this component.
Should the body be evaluated again?
NOTE: has a parameter to determine to pop the component stack.
assert(body != null);
try {
writer.write(body);
} catch (IOException e) {
throw new StrutsException("IOError while writing the body: " + e.getMessage(), e);
}
if (popComponentStack) {
popComponentStack();
}
return false;
|
protected org.apache.struts2.StrutsException | fieldError(java.lang.String field, java.lang.String errorMsg, java.lang.Exception e)Constructs?a RuntimeException based on the given information.
A message is constructed and logged at ERROR level before being returned
as a RuntimeException .
String msg = "tag '" + getComponentName() + "', field '" + field + ( id != null ?"', id '" + id:"") +
( parameters != null && parameters.containsKey("name")?"', name '" + parameters.get("name"):"") +
"': " + errorMsg;
throw new StrutsException(msg, e);
|
protected org.apache.struts2.components.Component | findAncestor(java.lang.Class clazz)Finds the nearest ancestor of this component stack.
Stack componentStack = getComponentStack();
int currPosition = componentStack.search(this);
if (currPosition >= 0) {
int start = componentStack.size() - currPosition - 1;
//for (int i = componentStack.size() - 2; i >= 0; i--) {
for (int i = start; i >=0; i--) {
Component component = (Component) componentStack.get(i);
if (clazz.isAssignableFrom(component.getClass()) && component != this) {
return component;
}
}
}
return null;
|
protected java.lang.String | findString(java.lang.String expr)Evaluates the OGNL stack to find a String value.
return (String) findValue(expr, String.class);
|
protected java.lang.String | findString(java.lang.String expr, java.lang.String field, java.lang.String errorMsg)Evaluates the OGNL stack to find a String value.
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.
if (expr == null) {
throw fieldError(field, errorMsg, null);
} else {
return findString(expr);
}
|
protected java.lang.Object | findValue(java.lang.String expr)Finds a value from the OGNL stack based on the given expression.
Will always evaluate expr against stack except when expr
is null. If altsyntax (%{...}) is applied, simply strip it off.
if (expr == null) {
return null;
}
if (altSyntax()) {
// does the expression start with %{ and end with }? if so, just cut it off!
if (expr.startsWith("%{") && expr.endsWith("}")) {
expr = expr.substring(2, expr.length() - 1);
}
}
return getStack().findValue(expr);
|
protected java.lang.Object | findValue(java.lang.String expr, java.lang.String field, java.lang.String errorMsg)Evaluates 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
a RuntimeException is thrown constructed with a
messaged based on the given field and errorMsg paramter.
if (expr == null) {
throw fieldError(field, errorMsg, null);
} else {
Object value = null;
Exception problem = null;
try {
value = findValue(expr);
} catch (Exception e) {
problem = e;
}
if (value == null) {
throw fieldError(field, errorMsg, problem);
}
return value;
}
|
protected java.lang.Object | findValue(java.lang.String expr, java.lang.Class toType)Evaluates the OGNL stack to find an Object of the given type. Will evaluate
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.
if (altSyntax() && toType == String.class) {
return TextParseUtil.translateVariables('%", expr, stack);
} else {
if (altSyntax()) {
// does the expression start with %{ and end with }? if so, just cut it off!
if (expr.startsWith("%{") && expr.endsWith("}")) {
expr = expr.substring(2, expr.length() - 1);
}
}
return getStack().findValue(expr, toType);
}
|
private java.lang.String | getComponentName()Get's the name of this component.
Class c = getClass();
String name = c.getName();
int dot = name.lastIndexOf('.");
return name.substring(dot + 1).toLowerCase();
|
public java.util.Stack | getComponentStack()Get's the component stack of this component.
Stack componentStack = (Stack) stack.getContext().get(COMPONENT_STACK);
if (componentStack == null) {
componentStack = new Stack();
stack.getContext().put(COMPONENT_STACK, componentStack);
}
return componentStack;
|
public java.lang.String | getId()Get's the id for referencing element.
return id;
|
public java.util.Map | getParameters()Get's the parameters.
return parameters;
|
public com.opensymphony.xwork2.util.ValueStack | getStack()Get's the OGNL value stack assoicated with this component.
return stack;
|
protected void | popComponentStack()Pops the component stack.
getComponentStack().pop();
|
public void | setActionMapper(org.apache.struts2.dispatcher.mapper.ActionMapper mapper)
this.actionMapper = mapper;
|
public void | setId(java.lang.String id)
if (id != null) {
this.id = findString(id);
}
|
public boolean | start(java.io.Writer writer)Callback for the start tag of this component.
Should the body be evaluated?
return true;
|
protected java.lang.String | toString(java.lang.Throwable t)Constructs a string representation of the given exception.
FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
PrintWriter wrt = new PrintWriter(bout);
t.printStackTrace(wrt);
wrt.close();
return bout.toString();
|
public boolean | usesBody()Overwrite to set if body shold be used.
return false;
|