Women in Technology

Hear us Roar



Article:
  Using the Validator Framework with Struts
Subject:   Decoupling from Struts
Date:   2003-02-26 10:22:40
From:   anonymous2
Hello,


Nice article. One thing I was hoping to learn from the article is how to write custom Validators that are decoupled from Struts, yet provide the same functionality as those validators shipped with Struts.
For instance, in the NewValidator class in the article there is a validateDrinkingAge(...) method that takes the following types as parameters:
Object
ValidatorAction
Field
ActionErrors
HttpServletRequest


Because of presence of ActionErrors, this NewValidator class is tied to Struts.
What happens when one day we decide to replace Struts with XYZ? We have to rewrite a piece of this Validator.


Because of presence of HttpServletRequest, this NewValidator is usable only in the Web App context. What happens if we want to use this Validator in a desktop application?


I am wondering how one would create a custom Validator that did not have these 2 dependencies (or at least not the Struts dependency).


If I write a custom Validator with a method such as:
validateDrinkingAge(Object, Field)


How do I use this method in a Struts application without passing it instances Struts-specific classes, such as ActionErrors, and still somehow end up with error messages suitable for showing to the user, etc.?


Thanks.


Main Topics Oldest First

Showing messages 1 through 2 of 2.

  • Decoupling from Struts
    2003-12-05 07:50:53  anonymous2 [View]

    It sounds like you'd want to look at the Jakarta Commons Validator framework, http://jakarta.apache.org/commons/validator/



  • Decoupling from Struts
    2003-06-26 10:30:07  anonymous2 [View]

    I've been trying to understand how to write custom Validators that are decoupled from Struts for days. Finally, I downloaded Jakarta Validator (package Commons) and I examined the example subdirectory. The example is pretty clear.

    Bye