Hi Math!

Mathieu Avoine wrote:
> 
> I want to use annotation driven validation to validate that a property 
> of type List contains at least 1 item (i.e. mylist.size() > 0).
> 
> I tried using required=true, because I would have expected the behavior 
> for a List object to check for the size, but it looks like it only 
> validates if the property is not null (am I right?).
> 

required=true should work. Make sure you're not creating an empty List
yourself; let Stripes take care of it, as in

private List<Integer> selectedIds;

not

private List<Integer> selectedIds = new ArrayList<Integer>();

If required=true doesn't work, let me know, maybe with the relevant code
that you are using.


Mathieu Avoine wrote:
> 
> So I turned to 
> expressions, and put up this one:
> 
> @ValidateNestedProperties({
> @Validate(field="selectedIds", required=true, 
> on={"goToSelectVehicles","activate"}, expression="this != null && 
> this.size > 0")
> })
> private PickList keys = null;
> 

Actually, expression="not empty this" would be the expression to use, except
that it won't work because expression validations are only executed if the
user submitted a value. If the user submitted a value, then the list
shouldn't be empty. So really this is a required=true validation.

Give it another try, and if it still doesn't work, post the JSP code for the
input field and the property code from PickList, I'll try to see what the
problem is.

Cheers,
Freddy

-- 
View this message in context: 
http://www.nabble.com/validating-list-size-tp16312747p16377586.html
Sent from the stripes-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to