• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it..

Thank You very much for your help.
 
A tiny monkey bit me and I got tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic