You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Taras Tielkes <ta...@info.nl> on 2002/09/13 13:30:19 UTC

Trying to use Validator stand-alone

Hi,

I'm trying to use the Commons-Validator in a stand-alone program.

My xml file is as follows:

<form-validation>
    <formset>
        <form name="emailForm">
            <field property="value" depends="required"/>
        </form>
    </formset>   
</form-validation>

My code looks like this:

	public class Bean {
		protected String value = null;
    
		public String getValue() {
			return value;
		}
    
		public void setValue(String value) {
			this.value = value;
		}
	}
	
	...
	protected static String FORM_KEY = "emailForm";
	...

	ValidatorResources res =
ValidatorResourcesInitializer.initialize("validation.xml");
	Validator validator = new Validator(res, FORM_KEY);

	Bean b = new Bean();
	b.setValue("a@b.c");	// It makes no difference if I set the field
or not

	validator.addResource(Validator.BEAN_KEY, b);
	ValidatorResults results = validator.validate();

	Map rm = results.getResultValueMap();

The map that I get back at this point is empty.

I assume I'm doing something wrong in the code fragment above. Can anyone
see what exactly?

Thanks in advance,

tt

	
	


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>