The following features are supported:
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 var attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.
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 Parampublic class Order { private Header header; private List<OrderItem> orderItems; } public class Header { private Long customerNumber; private String customerName; } public class OrderItem { private long productId; private Integer quantity; private double price; }
Smooks smooks = new Smooks(); Bean orderBean = new Bean(Order.class, "order", "/order"); orderBean.bindTo("header", orderBean.newBean(Header.class, "/order") .bindTo("customerNumber", "header/customer/@number") .bindTo("customerName", "header/customer") ).bindTo("orderItems", orderBean.newBean(ArrayList.class, "/order") .bindTo(orderBean.newBean(OrderItem.class, "order-item") .bindTo("productId", "order-item/product") .bindTo("quantity", "order-item/quantity") .bindTo("price", "order-item/price")) ); smooks.addVisitors(orderBean);And the execution code:
JavaResult result = new JavaResult(); smooks.filterSource(new StreamSource(orderMessageStream), result); Order order = (Order) result.getBean("order");@author tom.fennelly@jboss.com @see Value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|