Hi,
I am using struts2 on my current project and find ModelDriven interface very 
inconvenient. The intent of the interface is documented as, "it helps directly 
populating domain model". But if the domain model is little more complex than a 
simple bean, it becomes very inconvinient. e.g.
If my domain model is as follows
class Order {   String orderNumber;   UserInformation user;     }
class UserInformation {   String firstName;   String lastName;   Address 
address;}
class Address {   String addressLine1;   String city;   String state;}
The problem with ModelDriven is that I have to use OGNL expressions like 
user.address.addressLine1 in my HTML form. While this is not a bigger issue for 
the simple example as above, it can be awkward for little more complex domain 
models. What suits better for those domain models is to have a builder, which 
has setters for all the parameters on the form and has responsibility to build 
the actual domain model objects. Something like following
class OrderBuilder {  String orderNumber;  String firstName;  String lastName;  
String addressLine1;  String city;  String state;   public Order build() {    
......  }  }

I can offcourse use this builder as Model, fooling struts framework like 
following
class MyAction imeplements ModelDriven<OrderBuilder> {  private OrderBuilder 
builder;   public OrderBuilder getModel() {
           builder = new OrderBuilder();           return builder;    }
   public void execute() {         orderBuilder.build(); // Then use order   }} 
But I think this reads very badly. Instead, will it make more sense to have a 
annotation for "parameter mapping strategy"? Something like
Instead ofclass MyAction implements ModelDriven<Order>
have following
@BeanMappingStrategy(beanName="order")  //expects OGNL in parameter names to 
map to beanclass MyAction {  Order order;}
or 
@BuilderMappingStrategy(builderName="oderBuilder") // knows that its dealing 
with builder, so will call build method.class MyAction {  OrderBuilder 
orderBuilder;}
What do you guys think?
Thanks,Unmesh
_________________________________________________________________
Live Search extreme As India feels the heat of poll season, get all the info 
you need on the MSN News Aggregator
http://news.in.msn.com/National/indiaelections2009/aggregator/default.aspx

Reply via email to