There are a couple of ways. Personally, I advocate the lazy initialization
approach. Basically, your getter for the collection looks something like

if (collection == null) {
    collection = doSomethingToMakeTheCollection();
}

return collection;

Another way to do it -- one which many prefer -- is to use Stripes'
@Before(stages=LifecycleStage.BindingAndValidation) on a method that
initializes the collection. That will ensure the collection is initialized
whether validation succeeds or fails.

-Ben

On Sun, Jun 6, 2010 at 6:45 AM, daniel cioriia <danielcior...@yahoo.com>wrote:

> Hello,
>
> I have the folowing problem: I want to validate some of the fields from my
> action bean. I have validated them using the ValidateNestedProperties
> annotation and everything is working well, but the problem I am facing is
> that the stripes-select fields from the jsp don't get populated. I have
> investigated and the problem appears because the sourcePage parameter points
> to the jsp page, so when Stripes performs the validation and it finds
> errors, it creates a ForwadResolution to the jsp page that is referred  to
> into the sourcePage parameter. But now the problem is that the jsp uses a
> collection provided by the ActionBean to populate the select, so because the
> forward resolution to the jsp page does not come from the ActionBean the
> collection is not set and nothing appears in the select when the page with
> errors is displayed to the users.
> For example, for the jsp below:
>
> <stripes:form action="/AddOrganisation.action">
>  <stripes:errors/>
> <stripes:label for="name"/>
> <stripes:text name="organisation.name"/>
> <stripes:label for="orgType"/>
> <stripes:select name="organisation.orgType.id">
> <stripes:options-collection
> collection="${requestScope.actionBean.allTypes}" label="name" value="id"/>
> </stripes:select>
> <stripes:label for="individual" />
> <stripes:select name="organisation.individual" multiple="multiple">
> <stripes:options-collection
> collection="${requestScope.actionBean.allIndividuals}" label="title"
> value="id"/>
> </stripes:select>
> <stripes:submit name="save"/>
> <stripes:reset name="Reset"/>
> </stripes:form>
>
> the collection ${requestScope.actionBean.allTypes} comes from the
> ActionBean and it is set correctly the first time. But, if there are
> validation errors the page will be displayed to the user and since the user
> is forwarded to the page by stripes not by the action bean the collection
> allTypes it is empty.
>
> How should I manage this situation?
>
> Thanks,
> Dan
>
>
>
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit.  See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to