Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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

    public class Component

extends java.lang.Object

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 java.lang.String` | `COMPONENT_STACK`
`protected java.util.Map` | `parameters`
`protected ValueStack` | `stack`
`protected boolean` | `throwExceptionOnELFailure`

Constructor Summary
`Component(ValueStack stack)` Constructor.

Method Summary
`void` | `addAllParameters(java.util.Map params)` Adds all the given parameters to this component's own parameters.
`void` | `addParameter(java.lang.String key, java.lang.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 java.lang.String` | `completeExpressionIfAltSyntax(java.lang.String expr)` Adds the sorrounding %{ } to the expression for proper processing.
`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.
`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, boolean forceAddSchemeHostAndPort, boolean escapeAmp)` Renders an action URL by consulting the `ActionMapper`.
`protected java.lang.String` | `determineNamespace(java.lang.String namespace, ValueStack stack, javax.servlet.http.HttpServletRequest req)` Determines the namespace of the current page being renderdd.
`boolean` | `end(java.io.Writer writer, java.lang.String body)` Callback for the end tag of this component.
`protected boolean` | `end(java.io.Writer writer, java.lang.String body, boolean popComponentStack)` Callback for the start tag of this component.
`protected StrutsException` | `fieldError(java.lang.String field, java.lang.String errorMsg, java.lang.Exception e)` Constructs a `RuntimeException` based on the given information.
`protected Component` | `findAncestor(java.lang.Class clazz)` Finds the nearest ancestor of this component stack.
`protected java.lang.String` | `findString(java.lang.String expr)` Evaluates the OGNL stack to find a String value.
`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.
`protected java.lang.String` | `findStringIfAltSyntax(java.lang.String expr)` This check is needed for backwards compatibility with 2.1.x
`protected java.lang.Object` | `findValue(java.lang.String expr)` Finds a value from the OGNL stack based on the given expression.
`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.
`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.
`java.util.Stack` | `getComponentStack()` Gets the component stack of this component.
`java.util.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(java.lang.String throwException)`
`boolean` | `start(java.io.Writer writer)` Callback for the start tag of this component.
`protected java.lang.String` | `stripExpressionIfAltSyntax(java.lang.String expr)` If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.
`static java.lang.String` | `stripExpressionIfAltSyntax(ValueStack stack, java.lang.String expr)` If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.
`protected java.lang.String` | `toString(java.lang.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

### COMPONENT_STACK

    public static final java.lang.String COMPONENT_STACK

See Also:
  Constant Field Values

### stack

    protected ValueStack stack

### parameters

    protected java.util.Map parameters

### actionMapper

    protected ActionMapper actionMapper

### throwExceptionOnELFailure

    protected boolean throwExceptionOnELFailure

Constructor Detail

### Component

    public Component(ValueStack stack)

  Constructor.

  Parameters:
    `stack` - OGNL value stack.

Method Detail

### setActionMapper

    public void setActionMapper(ActionMapper mapper)

### setThrowExceptionsOnELFailure

    public void setThrowExceptionsOnELFailure(java.lang.String throwException)

### getStack

    public ValueStack getStack()

  Gets the OGNL value stack assoicated with this component.

  Returns:
    the OGNL value stack assoicated with this component.

### getComponentStack

    public java.util.Stack getComponentStack()

  Gets the component stack of this component.

  Returns:
    the component stack of this component, never `null`.

### start

    public boolean start(java.io.Writer writer)

  Callback 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

### end

    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.

  Parameters:
    `writer` - the output writer.
    `body` - the rendered body.
  Returns:
    true if the body should be evaluated again

### end

    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.

  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

### popComponentStack

    protected void popComponentStack()

  Pops the component stack.

### findAncestor

    protected Component findAncestor(java.lang.Class clazz)

  Finds 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.

### findString

    protected java.lang.String findString(java.lang.String expr)

  Evaluates the OGNL stack to find a String value.

  Parameters:
    `expr` - OGNL expression.
  Returns:
    the String value found.

### findString

    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.

  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`.

### fieldError

    protected 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`.

  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`.

### findValue

    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.

  Parameters:
    `expr` - the expression. Returns `null` if expr is null.
  Returns:
    the value, `null` if not found.

### stripExpressionIfAltSyntax

    protected java.lang.String stripExpressionIfAltSyntax(java.lang.String expr)

  If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.

  Parameters:
    `expr` - the expression (must be not null)
  Returns:
    the stripped expression if altSyntax is enabled. Otherwise the parameter expression is returned as is.

### stripExpressionIfAltSyntax

    public static java.lang.String stripExpressionIfAltSyntax(ValueStack stack,
                                                              java.lang.String expr)

  If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.

  Parameters:
    `stack` - the ValueStack where the context value is searched for.
    `expr` - the expression (must be not null)
  Returns:
    the stripped expression if altSyntax is enabled. Otherwise the parameter expression is returned as is.

### altSyntax

    public static boolean altSyntax(ValueStack stack)

  Is the altSyntax enabled? [TRUE]

  Parameters:
    `stack` - the ValueStack where the context value is searched for.
  Returns:
    true if altSyntax is activated. False otherwise. See `struts.properties` where the altSyntax flag is defined.

### altSyntax

    public boolean altSyntax()

  Is the altSyntax enabled? [TRUE]

  See `struts.properties` where the altSyntax flag is defined.

### completeExpressionIfAltSyntax

    protected java.lang.String completeExpressionIfAltSyntax(java.lang.String expr)

  Adds the sorrounding %{ } to the expression for proper processing.

  Parameters:
    `expr` - the expression.
  Returns:
    the modified expression if altSyntax is enabled, or the parameter expression otherwise.

### findStringIfAltSyntax

    protected java.lang.String findStringIfAltSyntax(java.lang.String expr)

  This check is needed for backwards compatibility with 2.1.x

  Parameters:
    `expr` - the expression.
  Returns:
    the found string if altSyntax is enabled. The parameter expression otherwise.

### findValue

    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.

  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`.

### findValue

    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.

  Parameters:
    `expr` - OGNL expression.
    `toType` - the type expected to find.
  Returns:
    the Object found, or `null` if not found.

### determineActionURL

    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,
                                                  boolean forceAddSchemeHostAndPort,
                                                  boolean escapeAmp)

  Renders an action URL by consulting the `ActionMapper`.

  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.

### determineNamespace

    protected java.lang.String determineNamespace(java.lang.String namespace,
                                                  ValueStack stack,
                                                  javax.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`.

### copyParams

    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.

  Parameters:
    `params` - the parameters to copy.

### toString

    protected java.lang.String toString(java.lang.Throwable t)

  Constructs a string representation of the given exception.

  Parameters:
    `t` - the exception
  Returns:
    the exception as a string.

### getParameters

    public java.util.Map getParameters()

  Gets the parameters.

  Returns:
    the parameters. Is never `null`.

### addAllParameters

    public void addAllParameters(java.util.Map params)

  Adds all the given parameters to this component's own parameters.

  Parameters:
    `params` - the parameters to add.

### addParameter

    public void addParameter(java.lang.String key,
                             java.lang.Object value)

  Adds 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 assoicated with the key.

### usesBody

    public boolean usesBody()

  Overwrite to set if body shold be used.

  Returns:
    always false for this component.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.