• 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 Pass Data Between Model and Action

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic