Home > Guides > Tag Developers Guide > Struts Tags > Tag Reference > Generic Tag Reference > bean |
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.
Dynamic Attributes Allowed:false | |||||
Name | Required | Default | Evaluated | Type | Description |
---|---|---|---|---|---|
id | false | false | String | Deprecated. Use 'var' instead | |
name | true | false | String | The class name of the bean to be instantiated (must respect JavaBean specification) | |
var | false | false | String | Name used to reference the value pushed into the Value Stack |
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