1

I am developing an app using MVC pattern.

Controllers: servlets

Model: I am following DAO/DTO pattern for accessing database

View: simple JSP EL and JSTL

For accessing database I am using DAO pattern. I want to put validation method and a HashMap for error messages inside the DTO classes for validating FORM data, something similar to Putting validation method and hashmap into DTO.

My question is - this a right approach? If not what is an ideal way for doing this?

As a summary: I want to know real world solutions for server side form validation when we are using DAO/DTO pattern. Please help me.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Manish gour
  • 145
  • 3
  • 14
  • I would request you guys to answer this question @balusc, any idea please help... – Manish gour Jun 02 '13 at 11:15
  • 1
    Quote from the Wikipedia article about [DTO](http://en.wikipedia.org/wiki/Data_Transfer_Object) (emphasis mine): "... a DTO **does not have any behavior** except for storage and retrieval of its own data (accessors and mutators). DTOs are simple objects that **should not contain any business logic** that would require testing." By the way, in Java EE world (former J2EE) DTO pattern is often called just *Transfer Object (TO)*. Also see this nice description of the [**Transfer Object**](http://www.corej2eepatterns.com/Patterns2ndEd/TransferObject.htm), to better understand its usage scenarios. – informatik01 Nov 18 '13 at 14:51
  • As for the common scenario for returning error messages from the server side, see [this answer](http://stackoverflow.com/a/14638621/814702). – informatik01 Nov 18 '13 at 14:53

1 Answers1

0

I believe you need to treat separately the architecture you're implementing and the frameworks you're using to implement the architecture.

Java has a rich set of tools for working on the three standard tiers of your application and choices depend on some factors like expected load and server resources, if you have a two or three users application then it is just a matter of taste.

In terms of DAO/DTO then you have also some options, for example you can build your Data access layer with hibernate and then for your service layer API use DTO's. In this situation you probably want to use a tool for mapping between your domain model and your DTO's (for example jDTO Binder).

Another common approach is to use Spring JDBC Template, there you can go a little bit more crazy and use the same Domain objects as part of the Service layer API.

Finally, the truth is, you can do this by the book or you can do it completely different choice is based on your scenario, taste and experience.