You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Roland Berger <ro...@aloba.ch> on 2003/06/02 09:43:57 UTC

how to retreive results of the validate method?

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;
  }