Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can anyone please give me an example for using value objects in struts

 
rakshini nithya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
can anyone please give me an example for using value objects in struts
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you be precise in what you need ??
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about Form bean?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "official" name for this type of object is Transfer Object. Here is a link that explains about this pattern.

In Struts, the Transfer Object is used to transfer data between Model objects, or business objects and the view. Some have tried to make the ActionForm a transfer object, but this is not a good idea. You want your model objects to be completely free of any outside dependencies, and if you use a Struts ActionForm in this way, you make your model dependent on Struts.

The best practice is to create a POJO (Plain Old Java Object) that has no outside dependencies to use as a Transfer Object.

Here's an example:

1-User requests data for a single customer:
2-Request is routed to Action Class
3-Action instantiated a CustomerDAO object to get the data.
4-You have previously coded a CustomerDTO class to be used to transfer customer data to and from the model, and have coded a getCutomer() method on your CustomerDAO object that returns an instance of the CutstomerDTO object.
5- The Action class now has a reference to the instance of CustomerDTO that was returned. It now copies the data from the CustomerDTO into the ActionForm for the page you want to display. The BeanUtils.copyProperties() class can be useful for doing this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic