Class Bean

  extended by org.apache.struts2.components.Component
      extended by org.apache.struts2.components.ContextBean
          extended by org.apache.struts2.components.Bean

public class Bean
extends ContextBean

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 var attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.


 <-- in freemarker form -->
 [@s.bean name="org.apache.struts2.example.counter.SimpleCounter" var="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" var="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=""/]

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:

Field Summary
protected  java.lang.Object bean
protected static Logger LOG
protected  java.lang.String name
protected  ObjectFactory objectFactory
protected  ReflectionProvider reflectionProvider
Fields inherited from class org.apache.struts2.components.ContextBean
Fields inherited from class org.apache.struts2.components.Component
actionMapper, COMPONENT_STACK, parameters, stack, throwExceptionOnELFailure
Constructor Summary
Bean(ValueStack stack)
Method Summary
 void addParameter(java.lang.String key, java.lang.Object value)
          Adds the given key and value to this component's own parameter.
 boolean end( writer, java.lang.String body)
          Callback for the end tag of this component.
 void setName(java.lang.String name)
 void setObjectFactory(ObjectFactory objectFactory)
 void setReflectionProvider(ReflectionProvider prov)
 boolean start( writer)
          Callback for the start tag of this component.
Methods inherited from class org.apache.struts2.components.ContextBean
getVar, putInContext, setId, setVar
Methods inherited from class org.apache.struts2.components.Component
addAllParameters, altSyntax, altSyntax, completeExpressionIfAltSyntax, copyParams, determineActionURL, determineNamespace, end, fieldError, findAncestor, findString, findString, findStringIfAltSyntax, findValue, findValue, findValue, getComponentStack, getParameters, getStack, popComponentStack, setActionMapper, setThrowExceptionsOnELFailure, stripExpressionIfAltSyntax, stripExpressionIfAltSyntax, toString, usesBody
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected static final Logger LOG


protected java.lang.Object bean


protected java.lang.String name


protected ObjectFactory objectFactory


protected ReflectionProvider reflectionProvider
Constructor Detail


public Bean(ValueStack stack)
Method Detail


public void setObjectFactory(ObjectFactory objectFactory)


public void setReflectionProvider(ReflectionProvider prov)


public boolean start( writer)
Description copied from class: Component
Callback for the start tag of this component. Should the body be evaluated?

start in class Component
writer - the output writer.
true if the body should be evaluated


public boolean end( writer,
                   java.lang.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.

end in class Component
writer - the output writer.
body - the rendered body.
true if the body should be evaluated again


public void addParameter(java.lang.String key,
                         java.lang.Object value)
Description copied from class: Component
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.

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


public void setName(java.lang.String name)

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