Class 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.
- var - the stack's context name (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" 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="#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:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Objectprotected static final org.apache.logging.log4j.Loggerprotected Stringprotected ObjectFactoryprotected ReflectionProviderFields inherited from class org.apache.struts2.components.ContextBeanvarFields inherited from class org.apache.struts2.components.ComponentactionMapper, attributes, COMPONENT_STACK, devMode, escapeHtmlBody, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddParameter(String key, Object value) Adds the given key and value to this component's own parameter.booleanCallback for the end tag of this component.voidvoidsetObjectFactory(ObjectFactory objectFactory) voidbooleanCallback for the start tag of this component.Methods inherited from class org.apache.struts2.components.ContextBeangetVar, putInContext, setVarMethods inherited from class org.apache.struts2.components.ComponentaddAllAttributes, completeExpression, copyAttributes, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, stripExpression, toString, usesBody
- 
Field Details- 
LOGprotected static final org.apache.logging.log4j.Logger LOG
- 
bean
- 
name
- 
objectFactory
- 
reflectionProvider
 
- 
- 
Constructor Details- 
Bean
 
- 
- 
Method Details- 
setObjectFactory
- 
setReflectionProvider
- 
startDescription copied from class:ComponentCallback for the start tag of this component. Should the body be evaluated?
- 
endDescription copied from class:ComponentCallback for the end tag of this component. Should the body be evaluated again?
 NOTE: will pop component stack.
- 
addParameterDescription copied from class:ComponentAdds 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.- Overrides:
- addParameterin class- Component
- Parameters:
- key- the key of the new parameter to add.
- value- the value associated with the key.
 
- 
setName
 
-