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
Joined: Feb 15, 2005
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.
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.