jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes How to Pass Data Between Model and Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to Pass Data Between Model and Action" Watch "How to Pass Data Between Model and Action" New topic
Author

How to Pass Data Between Model and Action

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Sometimes when my Actions delegate tasks to some POJO classes in the Model, I need to transfer a set of closely related data e.g. a few primitives + a class+ a Collection. It seems that the "proper" OO design is to create a specific DTO class just for the purpose of returning data from Model to the Controller. This is acceptable if the model is remote like EJB. But is there any simplier way to avoid creating new classes just for the purpose of returning a set of data?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

Originally posted by Alec Lee:
It seems that the "proper" OO design is to create a specific DTO class just for the purpose of returning data from Model to the Controller.

Yes. This is the way I would do it.

But is there any simplier way to avoid creating new classes just for the purpose of returning a set of data?

Why do you want to avoid creating an object? It does have a purpose - as you noted: to transfer data.

The alternative is using a Map, but then you lose type safety. In my mind, this is much less productive and less maintainable than creating the object. In an IDE, creating a new object and generating the getters/setters doesn't take long at all.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Consider Paul's rocket mass heater.
 
subject: How to Pass Data Between Model and Action