2007/3/30, Toscano <[EMAIL PROTECTED]>:


countries = new DropDownChoice ("country",
                new Model() {
                    public List getObject() {
                        return getCountries();
                    }
                }, getCountries(),
                new CountryChoiceRenderer());



Skip the second getCountries() call - you don't need that - and also this
way you lose the selected country (check the javadoc for DDC). Wicket Models
may be hard to grasp at first, I suggest you read the wiki again.

Remember: component's are just components they don't (or at least shouldn't)
store domain objects. Models do that. If you pass a List to DropDownChoice
it will be wrapped in a static Model in the constructor and won't be
affected by later changes. If you pass in a Model which calls getCountries()
on each request - your Model will refresh the list on each request.

My solution for you would be to write:

countries = new DDC("country", new PropertyModel(this, "countries), new
CountryChoiceRenderer());

This of course needs a CompoundPropertyModel somewhere up the component tree
that stores a bean that has getCountry() and setCountry() methods... If you
want to store your selected country elsewhere, you will need something
similar to the following code:

countries = new DDC("country", new PropertyModel(countryBean,
"selectedCountry"), new PropertyModel(this, "countries), new
CountryChoiceRenderer());

--
János Cserép - [EMAIL PROTECTED]
Mobile: +36 20 4328730
Web: http://www.szeretgom.hu
Skype: cserepj
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to