commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roland Berger" <roland.ber...@aloba.ch>
Subject how to retreive results of the validate method?
Date Mon, 02 Jun 2003 07:43:57 GMT
Hi all

I'd like to use the Validation Framework outside of struts but I'm facing
some problems how to find out if the validation has faild or not after
calling the validate method of the Validator Class.


Does anybody know what to do after calling validate()? Below you can see how
I check if any of the validation failed. But I have the feeling that I do
things the validate method already does.
In sturts an ActionErrors object is added as a ressource to the Validator
object which contains the errors. How can I do similar things?
What does the validation framework do after calling the validate() method.


Thanks a lot

Roland


Code snippet how I find out if any of the validation has vaild.

  protected ValidatorResults validate ( String validationFormName, Object
bean ) throws ValidatorException {
    ValidatorResults tValidatorResults = null;
    Validator validator = new Validator ( getValidatorResources (),
validationFormName );
    validator.addResource ( Validator.BEAN_KEY, bean );
    tValidatorResults = validator.validate ();

    boolean result = true;
    Iterator tIterResultValueMap = tValidatorResults.get();
    while ( tIterResultValueMap.hasNext() ){
      String tPropertieName = (String)tIterResultValueMap.next();
      Iterator tIterActionMap =
tValidatorResults.getValidatorResult(tPropertieName).getActionMap().keySet()
.iterator();
      while (tIterActionMap.hasNext()){
        String tValidatorActionName = ( String ) tIterActionMap.next();
        boolean tIsValid =
tValidatorResults.getValidatorResult(tPropertieName).isValid(tValidatorActio
nName);
        result = result && tIsValid;
      }
    }
    .....
    .....
    return tValidatorResults;
  }


Mime
View raw message