Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Validation vs. Business Logic

In the manuscript I'm reading, I just ran into a diagram and overview of a layered architecture - and all of a sudden, it hit me. At work, most of our business rules are being implemented by Struts' Validator framework. In the case of indexed properties and more complicated rules, these reside in the validate() method of our action forms. So it's interesting to me that I'm using a business delegate to perform my business logic - when in actuality, all my delegates are doing is copying properties from a POJO to an ValidatorForm. So this begs the question - shouldn't validation (a.k.a business rules) be done wherever it is most convenient rather than only in the domain layer? Oh yeah, and most of this is just validation - our real business rules (comparing data for validation) takes place in Oracle stored procedures. And you know what - it works great!. So my opinion is - do whatever is easiest and makes the most sense.

Posted in Java at Apr 29 2003, 06:18:27 AM MDT 6 Comments
Comments:

I would say that if you only have a web-based interface to your app, you're fine. If there is also a thick client that goes straight to your service layer, you'd need duplicate validation code.

Posted by matt on April 29, 2003 at 02:20 PM MDT #

As long as it is intuitive where to find it from a maintenance perspective. I remember wasting hours looking for a bug in a web app, only to find the offending code in a JSP - ouch! The more places you have to look, the longer it may take to fix problems.

Posted by Jason on April 29, 2003 at 02:29 PM MDT #

You should probably put it in in server-side distributable components unless you know for sure that you will never need any UI other than the web (and in that case, why aren't you using PHP or something easier to deal with?).

Posted by Dave on April 29, 2003 at 02:48 PM MDT #

The standard response that I've read in several places is that you should do validation multiple times and redundantly in order to correctly maintain constraints in a multi-tier MVC architecture. This does seem unneccesarily complicated, though..

Posted by Colin Evans on April 29, 2003 at 09:04 PM MDT #

The manuscript refers to a layered architecture. I guess it would be an in incomplete exercise to attempt to build a layered architecture and then implement business validations in the validator (since the validatons would need to be duplicated should you add another web / webservices / swing client to work with your business layer). I personally would either implement a layered architecture fully (ie. implement the validations in the business layer) or not at all. Your opinion - do whatever is easiest and makes most sense could get (mis?)interpreted as stick the validation logic in validator but implement a business layer separately.

Posted by Dhananjay Nene on May 01, 2003 at 09:01 AM MDT #

Something kept on bothering me about my last comment. I would be most comfortable using validator for enforcing business validations so long as one had separate validator.xml equivalents for presentation and business rules, and the business validations were triggered from within the business layer (i.e. by having the business layer invoke the validator functionality directly instead of using the struts plugin/integration).

Posted by Dhananjay Nene on May 01, 2003 at 11:38 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed