On Fri, 22 May 2009 18:10:52 +0100
Alan Burlison <[email protected]> wrote:

> This is with reverence to Indexed Properties as defined on 
> http://www.stripesframework.org/display/stripes/Indexed+Properties
> 
> I have a form that has two rows of data, each row consisting of a 
> question and answer.  However each row is mandatory, so the normal
> use of indexed properties doesn't work, as it only validates
> non-empty rows:
> 
> @ValidateNestedProperties({
>    :
>    @Validate(field="securityQuestions.question", on="save",
>      required=true),
>    @Validate(field="securityQuestions.answer", on="save",
>      required=true),
>    :
> })
> 
> However if I explicitly index the properties like this:
> 
> @ValidateNestedProperties({
>    :
>    @Validate(field="securityQuestions[0].question", on="save",
>      required=true),
>    @Validate(field="securityQuestions[0].answer", on="save",
>      required=true),
>    @Validate(field="securityQuestions[1].question", on="save",
>      required=true),
>    @Validate(field="securityQuestions[1].answer", on="save",
>      required=true),
>    :
> })
> 
> Then it *does* actually check that the fields are non-empty, even
> though the Stripes documentation suggests this shouldn't work.

That's related to a bug I've been meaning to log.  The bug is not so
much that it does this validation when it shouldn't, but that it
doesn't do the validation that it should do for indexed properties.
Internally, the validation metadata for your "securityQuestions" field
is recorded in the metadata map as "foo.securityQuestions.question" etc
- without the index.

The problem I had is that because of that, the field-metadata tag does
not correctly disgorge metadata for the fields whose names contain the
index notation.  I've worked around that by dropping a hidden disabled
text field onto the form whose name lacks the index, and so then the
metadata tag gives me the beef and my Javascript can take it from there.

I don't know for sure that things work similarly in the other direction
(that is, when doing the validation), but from what you describe it
sure seems like a possibility.




-- 
--
Mike McNally <[email protected]>

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to