This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Beans for Transferring DynaActionForm to Biz Tier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Beans for Transferring DynaActionForm to Biz Tier" Watch "Beans for Transferring DynaActionForm to Biz Tier" New topic
Author

Beans for Transferring DynaActionForm to Biz Tier

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
We normally have String properties in our DynaActionForm, so we need to convert them to the ultimate type (e.g. BigDecimal). Besides, we shouldn't directly pass the ActionForm to the model. This comes to a need to create separate JavaBeans with the proper property type for the model for every (Dyna)ActionForm. However, are there any simple ways to carry this task? It seems that we need to repeat this manually in Action property by property. Is it possible to automate this creation?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There's no getting around having to write the Business-tier bean and having to instantiate it. However, there is a shortcut to populating it. Struts uses Apache Commons Bean utilities for some of its functions, and you can use them as well, since they're already in your classpath. One useful method is BeanUtils.copyProperties(). This method will copy properties of the same name from one bean to another with some minimal type conversion logic thrown in as well. Give it a try and see if it works for you.


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Yea...the translation back and forth can be a pain. On the plus side, it does provide some level of separation. If you were passing your data layer objects all the way up to the presentation then if somebody tweaked the name of a property in the data layer, that person would have to track down all usages in JSP files.

I have looked a little into the BeanUtils approach and it just did not seem that compelling to me. I guess I did not like that it forces you to use the same name on both sides and that if properties did not match up then you would not know until you spotted the problem at runtime.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beans for Transferring DynaActionForm to Biz Tier