1 Reply Latest reply on Aug 15, 2007 7:26 AM by Ning Zhao

    Handling context-based validation

    thatrichard Newbie

      I have a "Claim" object. Whether or not it is valid depends on what the user is trying to do.

      My person object will require payee information to be valid for the purpose of payment, but not otherwise.

      Ideally, I'd do something like this:

       public void makePayment(Party payee) {
       Payee validator = new PayeeValidator();
       if (validator.isValid(payee) {

      At the UI level, I want to show

      Valid person: yes/no
      Valid payee: yes/no
      Valid employee: yes/no

      where the yes/no value is determined by calling the relevant validator with the same person object.

      This seems to be a limitation of the annotation approach. i.e. you can only specify a set of rules that apply in all contexts.

      Anyone else feel the same way? Am I missing something?


        • 1. Re: Handling context-based validation
          Ning Zhao Apprentice

          You may want to try to make your validator object be aware of the current context/conversation/use case (pick a word which is appropriate for your situation). My own project does not have any validator object yet (all the constraint logic is either in entity beans or in the entity manager beans), but I imagine it is possible to put a field

          AppContext currentContext;

          AppConversation currentConversation;

          AppUseCase currentUseCase;

          in your validator. And also setter and getter for this field. Your other objects like Person object can call the setter to let the validator know the current context/conversation/use case before calling the validation method. So that the current current context/conversation/usecase information is available in your validator object. Conceptually it should work.

          You can put the names of all the app-specific context/conversation/use case in a enum to eliminate String typing errors in your java class. An example can be seen here: