You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Kienenberger <mk...@gmail.com> on 2005/10/21 22:10:51 UTC

Comparable validation design

I'm working on a greater-than validator, along the lines of the
tomahawk equalsValidator.

However, it occurs to me that it'd probably be better if one validator
could support ==, !=, >, <, =>, and =<

I'm wondering if anyone has suggestions for the best way to represent it.

<greaterThanValidator for="startDateInput"/> is what I'm currently doing.

Maybe something like

<comparableValidator for="startDateInput" operator="gt"/>

Operator values being "eq", "ne", "lt", "gt", "ge", and "le" in
addition to (or maybe instead of)  "==", "!=", ">", "<", "=>'", and
"=<".

I'd like to submit this to tomahawk, so I'm interested in making it as
useable as possible.

In my current specific use case, I'm comparing dates, so I'd want the
error to read "endDate must be after startDate" rather than a more
generic "endDate must be greater than startDate" so I'm wondering if
it also makes sense to specify an errorString attribute.

<comparableValidator for="startDateInput" operator="gt"
alternateOperatorName="after" />

I'm also planning on having the comparisons done using the Comparable
interface, so the validator would work only on objects implementing
Comparable (but that seems like it'd probably cover anything worth
comparing).

The one other issue I noticed when writing this is that
equalsValidator uses getValue() to read the foreign component's value.
  It seems to me that this would only work well if the foreign
component was before the current component in the component tree.  
Otherwise, getValue() would not contain the converted submitted value
from that component.   Instead you'd either get the last value, no
value, or maybe the unconverted value (not sure about this last
possiblity).

Anyone have any comments on the proposed design?

-Mike