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.
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.