wood burning stoves 2.0*
The moose likes Struts and the fly likes how to transfer the data from the form bean to the DTO in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to transfer the data from the form bean to the DTO in struts" Watch "how to transfer the data from the form bean to the DTO in struts" New topic
Author

how to transfer the data from the form bean to the DTO in struts

yerra reddy gatla
Greenhorn

Joined: Apr 25, 2006
Posts: 25
Hi Everybody,

I am new to struts, I started working on a project in struts.

I have a doubt regarding how to transfer data from the FormBean to DTO.

I am following the following procedure.

I am calling a method on Business delegate by passing ActionForm Object as argument in Action class. From Business Delegate I am calling corresponding DAO to perform the busines operation which will return the result to the Action class via Business Delegate.

But my BOSS told me that Instead of passing FormBean object directly to DAO from BusinessDelegate, He asked me to create a DTO and Transfer data from FormBean to DTO, and pass that DTO to DAO.

Now the problem is I am not getting How to transfer data from FormBean to DTO.

Also let me know how to Instatiate BusinessDelegate from Action Class. and where I have to pass DTO object( whether it is from Action class to BusinessDelegate from there to DAO or from BusinessDelegate to DAO).

I think My problem is clear.

I struck up with this problem..

Please clarify my doubt and help me in doing the project.

Thanks in Advance

Regards
Yerra Reddy Gatla
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What your boss is trying to do is help you separate the "model" layer represented by your BusinessDelegate and your DAO from the "controller" layer represented by your Struts Action class. In order for your model layer to be sufficiently removed, it must not utilize any struts classes or be dependent in any way upon struts. If you pass a Struts ActionForm as a parameter into one of these classes, you've broken this rule.

The solution, as your boss wisely suggests, is to create a DTO to transfer data between the controller and the model. To create this DTO, just create a POJO (Plain Old Java Object) that follows the JavaBean specification for properties and accessors. It should have properties of the same name and type as the properties in your ActionForm. Then use this object to pass data from your Action to your BusinessDelegate and from your BusinessDelegate to your DAO.

In the execute() method of your Action class, just instantiate the DTO and copy the properties from the ActionForm to the DTO. You can use the org.apache.commons.beanutils.BeanUtils class to help you with this. Since Struts uses it, it's already in your classpath and it has a copyProperties() static method that can copy all of the properties from your ActionForm to properties of the same name in your DTO. Once you have the populated DTO, you can then pass it as a parameter to your BusinessDelegate method.


Merrill
Consultant, Sima Solutions
yerra reddy gatla
Greenhorn

Joined: Apr 25, 2006
Posts: 25
I got it..

Thank You very much for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to transfer the data from the form bean to the DTO in struts
 
Similar Threads
Doubt in MVC
struts DAO layer and DTO objects
Implementing Patterns
Design issue (POJO and DTO/VO)
Struts and App Design question