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 Bean

    java.lang.Object
      org.apache.struts2.components.Component
          org.apache.struts2.components.Bean

    public class Bean

extends Component

Instantiates a class that conforms to the JavaBeans specification. This tag has a body which can contain a number of `Param` elements to set any mutator methods on that class.

If the id attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.

- id - the stack's context id (if supplied) that the created bean will be store under
- name* - the class name of the bean to be instantiated (must respect JavaBean specification)

Examples:

     <-- in freemarker form -->
     [@s.bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter"]
       [s:param name="foo" value="BAR"/]
       The value of foo is : [s:property value="foo"/], when inside the bean tag.

     [/s:bean]

     <-- in jsp form -->
     <s:bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter">
       <s:param name="foo" value="BAR" />
       The value of foot is : <s:property value="foo"/>, when inside the bean tag <br />
     </s:bean>

This example instantiates a bean called SimpleCounter and sets the foo property (setFoo('BAR')). The SimpleCounter object is then pushed onto the Valuestack, which means that we can call its accessor methods (getFoo()) with the Property tag and get their values.

In the above example, the id has been set to a value of counter. This means that the SimpleCounter class will be placed into the stack's context. You can access the SimpleCounter class using a Struts tag:

     <-- jsp form -->
     <s:property value="#counter" />

     <-- freemarker form -->
     [s:property value="#counter.foo"/]

In the property tag example, the # tells Ognl to search the context for the SimpleCounter class which has an id(key) of counter

See Also:
  `Param`

Field Summary
`protected Object` | `bean`
`protected static Log` | `log`
`protected String` | `name`
`protected ObjectFactory` | `objectFactory`

Fields inherited from class org.apache.struts2.components.Component
`actionMapper, COMPONENT_STACK, id, parameters, stack`

Constructor Summary
`Bean(ValueStack stack)`

Method Summary
`void` | `addParameter(String key, Object value)` Add's the given key and value to this components own parameter.
`boolean` | `end(Writer writer, String body)` Callback for the end tag of this component.
`void` | `setName(String name)`
`void` | `setObjectFactory(ObjectFactory objectFactory)`
`boolean` | `start(Writer writer)` Callback for the start tag of this component.

Methods inherited from class org.apache.struts2.components.Component
`addAllParameters, altSyntax, copyParams, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getId, getParameters, getStack, popComponentStack, setActionMapper, setId, toString, usesBody`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    protected static Log log

### bean

    protected Object bean

### name

    protected String name

### objectFactory

    protected ObjectFactory objectFactory

Constructor Detail

### Bean

    public Bean(ValueStack stack)

Method Detail

### setObjectFactory

    public void setObjectFactory(ObjectFactory objectFactory)

### start

    public boolean start(Writer writer)

  Description copied from class: `Component`
  Callback for the start tag of this component. Should the body be evaluated?

  Overrides:
    `start` in class `Component`
  Parameters:
    `writer` - the output writer.
  Returns:
    true if the body should be evaluated

### end

    public boolean end(Writer writer,
                       String body)

  Description copied from class: `Component`
  Callback for the end tag of this component. Should the body be evaluated again?

  NOTE: will pop component stack.

  Overrides:
    `end` in class `Component`
  Parameters:
    `writer` - the output writer.
    `body` - the rendered body.
  Returns:
    true if the body should be evaluated again

### addParameter

    public void addParameter(String key,
                             Object value)

  Description copied from class: `Component`
  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.

  Overrides:
    `addParameter` in class `Component`
  Parameters:
    `key` - the key of the new parameter to add.
    `value` - the value assoicated with the key.

### setName

    public void setName(String name)

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-2007 Apache Software Foundation. All Rights Reserved.