struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Unmesh joshi <unmesh_jo...@hotmail.com>
Subject Usecases for ModelDriven interface
Date Tue, 05 May 2009 17:47:09 GMT

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 of
class MyAction implements ModelDriven<Order>

have following

@BeanMappingStrategy(beanName="order") //expects OGNL in parameter names to map to bean
class 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

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/india/windows/windowslive/photos.aspx
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message