[Stripes-users] Validate on Event

Subject:   [Stripes-users] Validate on Event (find more)
From:   "\"Grék, Jan\"" <hidden> (find more)
Date:   Feb 01, 2006 14:50

Hi Tim, hi All !

There has been no such thing like "validate on event" in Stripes. I
think that this small feature might be very usefull. Let's say we have
an User-Details Form and  User-Edit Form.
User-Details Form has got following fields: email, username, password
and role.
User-Edit Form has got: email, username b/c of the obvous reasons (many
roles, password can't be editied even by admin).
I'd like to handle both usecases by a single ActionBean - obvuously I
need to validate slightly different.
I think a solution to this problem might be a new property on Validate
annotation like restrictToEvent="create" which means this should behave,
like there is no validation at all when event is different.
e.i.: Validate(field="password", required="true", restrictToEvent="create")
!: Don't forget the property will be still bound.

I had to change OgnlActionBeanPropertyBinder just on two places and it
seems to work. I attached the code. (Changes are commented "// CHANGED
BEGIN/END").

I would rather that validations were more simple/safe,  like
restristToEvent would not be bound at all on other events. So we might
come to the idea of having more validations on a single property like this:

Validate(field="password", required="true", restrictToEvent="create")
Validate(field="password", restrictToEvent="update", ignore="true")
public void setPassword(String password){}
, however more validations on single property are not allowed at the
time being.

To be honest I must say I would like to see Stripes having deployable
Hibernate Validations as well - to validate just once. However there are
no "nested validations" in HV as far
as I know (correct me if I am wrong).

I hope you will find this small feature useful, it may save you from
writing a lot of code:-)

Regards
Jan