struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Unmesh joshi <unmesh_jo...@hotmail.com>
Subject RE: ModelDriven, a wrong choice of interface?
Date Tue, 05 May 2009 01:06:22 GMT

> Please ask these questions on the users list. This list is for the
> development of struts itself.
> 
> musachy

I was more interested in knowing what struts developers think of ModelDriven interface. Use
of ModelDriven interface is awkward at times.I thought allowing users to provide strategy
for parameter mapping as metadata, like I have shown in my email, can be more useful and cleaner.

Thanks,Unmesh 

> Date: Mon, 4 May 2009 09:12:10 -0400
> Subject: Re: ModelDriven, a wrong choice of interface?
> From: musachy@gmail.com
> To: dev@struts.apache.org
> 
> Please ask these questions on the users list. This list is for the
> development of struts itself.
> 
> musachy
> 
> On Sun, May 3, 2009 at 8:52 PM, Unmesh joshi <unmesh_joshi@hotmail.com> wrote:
> >
> > 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
> 
> 
> 
> -- 
> "Hey you! Would you help me to carry the stone?" Pink Floyd
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
> 

_________________________________________________________________
Planning the weekend ? Here’s what is happening in your town.
http://msn.asklaila.com/events/
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message