I've been writing my own Validator<String,String> to match one Field to
another. And I've managed to figure out how to get my hands on the Component
representing the Field I'm trying to match with.
However, I've not been able to figure out how to get the actual value of
that other Field. Here's the relevant code I've been using:

   public void validate(Field field, String constraintValue,
MessageFormatter formatter, String value) throws ValidationException {
       //Gain access to the component-tree
       Component page =
((Component)field).getComponentResources().getPage();
       //Grab hold of our target
       Component comp = getNestedComponent(page, constraintValue);
       //Introspection to see if we find a match, this still fails horribly
:(
       if (comp instanceof AbstractTextField) {
           AbstractTextField targetField = (AbstractTextField)comp;
           log.info("Checking if " + value + " matches with the value of "
+ constraintValue);
           if (!value.equals(tracker.getInput(targetField))) throw new
ValidationException(buildMessage(formatter, field));
       } else {
           log.info("Matching is not an AbstractTextField but is: " +
comp.getComponentResources().getElementName());
           throw new ValidationException(buildMessage(formatter, field));
       }
   }

Where getNestedComponent(Component, String) is a method to search through
the component model deeper than the current level. The Component I find is
most definitely the other field I was looking for, but it doesn't seem to be
an instanceof AbstractTextField, which is the least I had expected it to be.
And yes, I'm aware that validation always fails with the current
implementation, I wanted it like the to test it properly.

Gr,

Martin

Reply via email to