Hi everyone.
We have a web application that uses all of the main components of the J2EE architecture - namely:
1) Java Servlet controller (with JavaBeans)
2) JSP (View) (with JavaBeans)
3) Session EJBs with business logic/shopping cart
4) Entity EJBs (Model)
5) Value Objects for performance reasons
So, suppose, a customer has to register and provide details of name, addresss and few more bits and pieces. Let's suppose name and 2 lines of the address are mandatory.
Now - WHERE DO I PUT THE VALIDATION?
a) In the Servlet controller?
b) In the JavaBeans representing the data in the web container?
c) In the value object
d) In the Entity EJB
e) In ALL or a COMBINATION of the above
I'm rightly confused here as to the best approach. I obviously do not want to be duplicating logic, if at all possible, yet I want good and quick feedback to the user.
Can someone provide me with some guideance?
Thanks
Discussions
Web tier: servlets, JSP, Web frameworks: How to eliminate duplication of validation code
-
How to eliminate duplication of validation code (3 messages)
- Posted by: jimmy Crowley
- Posted on: November 29 2000 13:44 EST
Threaded Messages (3)
- How to eliminate duplication of validation code by Kapil Israni on November 30 2000 10:00 EST
- How to eliminate duplication of validation code by Arvind Sinha on December 01 2000 01:39 EST
- How to eliminate duplication of validation code by Kapil Israni on December 01 2000 09:04 EST
-
How to eliminate duplication of validation code[ Go to top ]
- Posted by: Kapil Israni
- Posted on: November 30 2000 10:00 EST
- in response to jimmy Crowley
hi jimmy,
i think the kind of validations u r talkin bout shud go in the enntity model. since the entity objects represent the actual data namely name, address etc. each entity objects shud validated itself.
for example u cud have a address entity with attributes like city, state, zip, address1, address2. now this entity shud validate it self by having a method validate which checks for the integrity of the data whether its null or not or minimum lengths etc.
i think this is thebest way to data integrity validation.
hope this helps. lemme know.
kapil -
How to eliminate duplication of validation code[ Go to top ]
- Posted by: Arvind Sinha
- Posted on: December 01 2000 01:39 EST
- in response to jimmy Crowley
The best way is to minimise the load on the server and do the validation on the client side. Therefore you can conveniently use javascript validation for length of the field, if the field is null or contains valid/invalid characters et.al.
This is definitely fast and reliable.
Hope this helps.
Arvind -
How to eliminate duplication of validation code[ Go to top ]
- Posted by: Kapil Israni
- Posted on: December 01 2000 09:04 EST
- in response to Arvind Sinha
Well client side validation is one solution, but the long term one and not the best one. since u have entity beans in ur application they shud be responsible for protecting the integrity of the data that they own.
a simple example what if tomorrow i want to write a WML/HDML (hand held devices) front-end to ur application using ur existing infrastructure(session beans/entity beans). does that mean i do that validation again for my handheld devices. i dont buy that. the idea is to write such a middle tier/application infrastructure that it can be ported with minimal effort to any front end.
and again i repeat since ur entity beans represent the data u want to validate they themselves shud be responsible of protecting the validity of that data. u dont want to delegate that task to someone else.
yes client side validation avoid that extra network trip u incur when u ask ur entity beans to validate the data. but i thing that extra network trip is worth it for the clean application u will get.
hope i have supported my logic well.
kapil