Hmm, so am I off in left field here? Is it not possible to validate
the contents of one field based on the contents of another, server-
side? Is there a bug?
Thanks,
J
On 1-Oct-06, at 8:31 PM, Julian Wood wrote:
I'm using a bean for validation. In particular, I want to make sure
that one field is lte another (think exam scores 6 out of 12). So I
have a bean set up like this:
<bean name="maxOne" lifecycle="none"
class="ca.ucalgary.commons.mt3.controller.MaxNullValidator">
<set name="max" value="ognl:record.rdg1Max"/>
</bean>
And components like this:
<component id="rdg1" type="TextField">
<binding name="value" value="ognl:record.rdg1"/>
<binding name="translator" value="translator:number"/>
<binding name="displayName" value="literal:rdg1"/>
<binding name="validators" value="beans.maxOne"/>
</component>
<component id="rdg1Max" type="TextField">
<binding name="value" value="ognl:record.rdg1Max"/>
<binding name="translator" value="translator:number"/>
<binding name="displayName" value="literal:rdg1 Max"/>
</component>
Template is like this:
<input jwcid="rdg1" class="score"/>
out of
<input jwcid="rdg1Max" class="score"/>
Now ignoring the actual validation, which is simple, when I render
this page, max is null as indicated by logging from the setter in
maxOne, as expected. When I submit, however, it is still null. When
the page comes back (after failing validation), the max is now set
properly, and simply pressing submit again will succeed.
The curious thing is if I do the same thing using Date, the date
will be null on pageRender, but will take the value of the date on
submit.
With String, I have had it go both ways, so I have been bashing my
head against the wall trying to figure out what the difference is,
to no avail. I know I must be missing something. I've been playing
with different object types and translators, but it all just
confuses the issue.
How do I make sure the setter for a bean validator is called
properly (for an Integer) before the validate method on the
validator is called? ie How do I ensure the behaviour seen for Date
also works for an Integer?
Thanks,
J
PS. I also know this would be easy using js, by overriding
renderContribution, but we need server-side too.
--
Julian Wood <[EMAIL PROTECTED]>
Software Engineer
Teaching & Learning Centre
University of Calgary
http://tlc.ucalgary.ca