01: /*
02: * Created on 12 Sep 2007
03: */
04: package uk.org.ponder.rsf.swf.support;
05:
06: import org.springframework.beans.BeansException;
07: import org.springframework.beans.factory.BeanFactory;
08: import org.springframework.beans.factory.BeanFactoryAware;
09: import org.springframework.validation.Validator;
10: import org.springframework.webflow.action.FormAction;
11:
12: import uk.org.ponder.springutil.validator.ValidatorCompostor;
13: import uk.org.ponder.springutil.validator.support.CompoundValidator;
14:
15: public class ValidatorFormAction extends FormAction implements
16: BeanFactoryAware {
17:
18: private ValidatorCompostor validatorComposter;
19:
20: private CompoundValidator compoundValidator = new CompoundValidator();
21:
22: private String[] validatorSpecs;
23:
24: public void setValidatorComposter(
25: ValidatorCompostor validatorComposter) {
26: this .validatorComposter = validatorComposter;
27: }
28:
29: public void setValidatorSpecs(String[] specs) {
30: this .validatorSpecs = specs;
31: }
32:
33: public void initAction() {
34: for (int i = 0; i < validatorSpecs.length; ++i) {
35: compoundValidator.addValidator(validatorComposter
36: .parseValidator(validatorSpecs[i]));
37: }
38: // Call this last since the darn thing asks for the Validator
39: super .initAction();
40: }
41:
42: public Validator parseValidator(String spec) {
43: return validatorComposter.parseValidator(spec);
44: }
45:
46: public Validator getValidator() {
47: Validator super val = super .getValidator();
48: if (super val == null)
49: return compoundValidator;
50: if (compoundValidator == null)
51: return super val;
52: return new CompoundValidator(super val, compoundValidator);
53: }
54:
55: // Temporary method - apparent bug in Spring 2.1M3 causes resolution of
56: // MessageSource to fail with NPE in the case this is done via a PostProcessor.
57:
58: public void setBeanFactory(BeanFactory beanFactory)
59: throws BeansException {
60: validatorComposter = (ValidatorCompostor) beanFactory
61: .getBean("validatorCompostor");
62: }
63: }
|