I have the same field referenced more than once in the same <form> section:
 
<field property="middleDate" depends="required,date,datenotafter">

<arg0 key="middleDate"/>

<arg1 key="contractEndDate"/>

<var><var-name>baseProperty</var-name><var-value>contractEndDate</var-value></var>

</field>

<<field property="middleDate" depends="required,date,datenotbefore">

<arg0 key="middleDate"/>

<arg1 key="contractStartDate"/>

<var><var-name>baseProperty</var-name><var-value>contractStartDate</var-value></var>

</field>

I have two tests for dates being ordered correctly. I want to see that the 
middle date is between the start and the end dates (inclusive). So I wrote two 
new tests that do the comparisons and either pass or fail depending on the 
ordering.

The problem I am seeing is that only one of the tests is being "done". Well, 
actually, they are both being done but the ValidatorResults object has a Map to 
hold the results with the key being the field name and after every test the new 
result is "merged" with the old. "Merge" in this case means "putAll()" is 
called on the Map and anything with the same name is either ignored or 
replaced. (I haven't really figured out which.) So the results of one of the 
tests is thrown out and the other one is preserved. This seems to work if both 
tests either fail or succeed. If one fails and one succeeds, I would expect the 
failure to be preserved at all times. If they both fail I guess the multiple 
failures should be stored inside the ValidatorResult that is in the Map.

If some better sort of merging isn't done in ValidatorResults it could at least 
detect that it is losing something and throw an exception saying you can't have 
two <field> entries with the same 'property' value.

Ok ... I may be missing something here? I didn't spend a long time perusing the 
source but that what it looks like is happening.

There may be a way of working around this. The first thing that pops into my 
mind is adding another new test that takes property names for two dates to form 
a range and tests the property against the range. The second thing is to give 
the 'baseProperty' two different names for the not-before and not-after tests 
so that both tests could happen in a single <field> section. (You know, with 
the commas.)

Does anyone see a better solution for me?

Thanks.

-- Lee Meador

Reply via email to