This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 30075
    
149

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to Pass Data Between Model and Action
 
Similar Threads
Setting ResultSet into an ArryList
Programming Style - How to Return A Set of Objects to Caller
Design pattern needed
Using a JComboBox to change the contents of another JComboBox
display a jsp in a popup window