Not possible?

Sometimes a validator needs to look at input from another field to see if it is valid (ie password/confirmPassword). I know it's easy to do in onValidateForm, but I'd like to see how to do it in a nice modular Validator. I'm looking for something like:

public void validate(Field field, String sourceFieldId, MessageFormatter formatter, Object value) throws ValidationException {
        Component page = ((AbstractField) field)._resources.getPage();
        try {
Method getter = page.getClass().getDeclaredMethod(getMethodName(sourceFieldId));
            String sourceValue = (String) getter.invoke(page);
            if (value == null || !value.toString().equals(sourceValue))
throw new ValidationException(buildMessage(formatter, field));
        } catch (Exception e) {
log.error("No public getter field in page for: " + sourceFieldId);
        }
    }


but can't do that (the only problem being the private _resources). How can that be done in a Validator? I can't inject anything. I don't actually need to make my own field which exposes the ComponentResources, do I?

Thanks.

J



On Mar 24, 2008, at 5:17 PM, Julian Wood wrote:

How can you get access to an arbitrary Field from inside a Validator, given its id? In t4 it was relatively easy to grab the form and from there grab a field.

Thanks,

J

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to