Announcement Announcement Module
Collapse
No announcement yet.
Validation on Controller vs Facade Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation on Controller vs Facade

    Our application has two kinds of validation

    1. You have the facade which validates our domain objects. This validates that everything meets our business requirments.

    2. Then there is the controller / form that has form specific elements and the domain object on it. So we need some kind of 'form' validation that validates the data on the form.

    Because the data on the form contains also our domain object we have validation method that can be found both on the facade as on the controller side.

    Now, I was just wondering how most of you handle validation in a multi layered application.

    Grtz

  • #2
    Assertion

    If I look at the Spring examples none of the public methods on dao or facades check if the input they receive is valid, let me clarify:

    public void doBlabla(String param) {
    ... some logic
    }

    Is this a best practise you advice or shouldn't it be better that you do something like, see below, when you except the param to have a valid input?

    public void doBlabla(String param) {
    Assert.notBlank(param);
    some logic
    }

    Otherwise for example you can pass null objects to your dao create method which results in stupid errors.

    This is propable a very novice and stupid question but .... that happens

    Comment


    • #3
      I guess each layer validates according to the contract between it and its serving layer? E.g., there are many ways to input a date, but the input contract between the presentation layer and the business layer is defined to be "a Date type object". So it's a form controller's burden to validate user inputs and to come up with a Date object - be it from a group of 3 text fields, a calendar control, etc. But once the business method gets the Date object for a parameter, it needs to validate further based on business logic and perhaps against existing data from the data layer, e.g., it must fall into a certain date range.

      Comment

      Working...
      X