File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Best Practise? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Best Practise?" Watch "Best Practise?" New topic
Author

Best Practise?

Bjorn Stove
Greenhorn

Joined: Jan 08, 2005
Posts: 19
Hi.
I have a best practise question.
I want to populate my actionForm with only String properties.
I have a dto that contains both Strings and Integers and so on.
If I only have one dto theres no problem. I can just use
beanutilities or just convert to the corresponding actionForm.
But if I recieve a collection of dto:s into my actionForm what is the
best practice to convert them to String properties, so that I can just use logic:iterate in my html page.

Best Regards
Bjorn
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd say the best solution would be to iterate over the collection and use BeanUtils to copy the poperties for each instance of the DTO to the corresponding instance of the object used by the ActionForm.

Bear in mind that if the DTO instances are not being modified, but just being displayed, it's perfectly OK just to include a collection of your DTO object in the ActionForm. If the instances are being modified, it's best to have a collection of another object with String properties that is used by the ActionForm.

Struts' need to ue String properties is kind of a pain. Other frameworks such as JSF, Webworks, and Stripes can handle properties of other types much more easily.


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
The "Best Practice" would be different for a collection of 10 items versus a collection of 10,000 items.

For pages like search results, my project used to do more of the "iterate over the data objects and create new display objects" approach but switched over to adding methods directly to the data object classes. For example, the data object might have the properties itemCost and purchaseDate and I would add in methods getFormattedItemCost and getFormattedPurchaseDate that used our utility methods to format the data.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best Practise?