Tag Name: <a2:bean />

Description

Instantiate a JavaBean and place it in the context.

Instantiates a class that conforms to the JavaBeans specification. This tag has a body which can contain a number of {@link 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.

Examples:

  <-- in freemarker form --> [ww.bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter"] [a:param name="foo" value="BAR"/] The value of foo is : [a:property value="foo"/], when inside the bean tag.
[/a:bean] <-- in jsp form --> <a:bean name="org.apache.struts2.example.counter.SimpleCounter" id="counter"> <a:param name="foo" value="BAR" /> The value of foot is : <a:property value="foo"/>, when inside the bean tag <br /> </a: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 called 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 WW's tag:

 <-- jsp form --> <a:property value="#counter" /> <-- freemarker form --> [a: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

Attributes

Name

Required

Default

Type

Description

name true   String the class name of the bean to be instantiated (must respect JavaBean specification)
id false   Object/String id for referencing element. For UI and form tags it will be used as HTML id attribute

Back to Taglib Index