I'm going to try to boil this down to the neccesities. If it doesn't
make sense, I'll provide some code.
I have a Foreach loop inside of a form. The loop generates a couple of
sets of FieldLabel/ValidField components*.
The problem is that two of the fields' validation depend on each other.
If both fields are empty, they both need to be marked as errored so that
the error markup will be written. If one or the other has a value, they
are both valid. Can someone point me in the best direction for this?
My first thought was to record the name of the ValidField component when
the page was getting the value for it. I would get the names, something
like validComponentName and validComponentName$0. At form rewind time,
though, I couldn't figure out how to get the components given those
names and set them in error. It seems impossible, given that getName()
will always return the most recent name generated for the component. I
tried going through the ValidationDelegate's FieldTrackings and going
through the map returned by getComponents(), neither of which worked
very well.
My next option was going to be to make a special validator for this
purpose. It would have to be a page property rather than a bean so that
the same validator would be used for both ValidFields. All of these
approaches seem ugly to me. Ideas? Directions?
-Chris
*uses a Defer type component to take care of the off by one validation
error. the Defer component wraps a FieldLabel and takes in a block that
contains a ValidField:
protected void renderComponent(IMarkupWriter writer, IRequestCycle
cycle)
{
IMarkupWriter nested = writer.getNestedWriter();
getBlock().renderBody(nested, cycle);
renderBody(writer, cycle);
nested.close();
}