You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John Reynolds <jo...@gmail.com> on 2004/11/10 00:42:41 UTC

FormTable: Row-level and Table-level validations

Please bear with this somewhat rambing posting...

I am trying to figure out the best way to do "row-level" validation on
a form table that has interdependent fields. For example, consider a
table where each row has two editable fields, startDate and endDate. 
I want to make sure that startDate is earlier then endDate.

I also need to figure out how to do "table-level" validation.  For
example, assume that each row must have a unique SSN.  I need to check
all the SSN on all the rows of the current page to make sure the user
didn't screw up.

I've tried several things that are listed at the end of this posting. 
I can "make this work", but I really want to know "the right way" to
do this.  My solutions all feel kludgey.

I am looking for solutions that will let me validate all of the input
on a page before updating the underlying datasource.  If any errors
are detected, I want to mark them in the table.

There are two prongs to this problem: Accessing all of the fields that
the user has changed and marking the fields that have errors.  I have
come up with several options for accessing the changes, but only after
the fields have already been rendered.  I don't know how to "mark" a
field after it has been rendered.

I have a couple of thoughts:
(1)  It would be nice if a row-level validator could be specified for
FormTableRows.  This validator would be executed for each row as soon
as all the user's changes are applied to the row.

(2) Table-level validation really requires access the updated data
objects for all the rows on the current page of the table before the
individual rows are rendered.  That way each validator for specific
fields could also check for row or table level validation errors.


====================================================================================================
Here's what I have tried....

I implemented each field as a ValidField and attached a custom
validator.  When my validator's toObject() method is executed I can
(through a series of steps) get to the object that represents the
"current" row.

The drawback to this approach is that the fields of the "current" row
object are updated in the order that the columns are displayed.  I
can't do my check until the after the last column has been validated.

To get around this column order dependency, I decided to add a
"hidden" component as the last column.  Unfortunately, the "hidden"
atttibute of ValidField just turns it into a password field.  Using a
"real" Hidden component is almost what I need, but it does not have a
validator.

The good news is that using this technique I can get all the values
that the user changed.  The bad news is that I don't know how to
"decorate" the offending fields... In the case where the start date is
after the end date I would really like to "decorate" both of the
fields... either one could be "wrong".

A more general question concerns all of the "row" objects that are
created as the table is rendered...  I have not discovered a standard
method to access the "converted row" objects when the form's listener
is executed (Apparently the FormTableRows component discards these
objects as each row is rendered).

While not necessary for "row-level" validation, being able to access
the modified rows would be helpful for "table-level" validation.

I came up with a work-around for this by explicity storing the objects
when my "hidden" component's listener is called... but this seems like
an error prone approach.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org