On 2013-11-19 08:44, Martin Grigorov wrote: > Hi, > > I think you can use IModel<String> for the dropdown. This will be the > country code. > The transformation from id to name and back (if needed) can be moved to a > custom IChoiceRenderer. There you have access to the current locale for > each rendering. > CountryChoiceRenderer can delegate the actual work to > CountryDatabase/CountryProvider/...
Thanks Martin for your reply! Using your suggestions I was able to simplify the Wicket code to two classes: a custom DropDownChoice and a renderer. As a drawback I had to optimize/cache query in my service returning country name by ID/code. One thing is not clear for me. How can I get a current locale in CountryChoiceRenderer (without pass it from my DropDownChoice component)? Marcin > On Tue, Nov 19, 2013 at 12:51 AM, Marcin Zajączkowski <msz...@wp.pl> wrote: > >> Hi, >> >> Working on Wicket frontend for AppFuse I had to implement a drop down >> choice of countries. I did it, but don't like the solution and I wonder >> if it could be done easier/prettier? >> >> Issues: >> 1. In domain model there is a country represented as a String field (a >> country code) in an address class. In my Wicket component I wanted to >> use a Country class with a code and name. It forced me to create >> CountryDropDownChoice component which embed String model into Country >> model(with EmbeddedCountryModel): >> >> public class CountryDropDownChoice extends DropDownChoice<Country> { >> public CountryDropDownChoice(String id, PropertyModel<String> >> country, Locale locale) { >> super(id, new EmbeddedCountryModel(country, locale), new >> CountriesModel(locale), new ChoiceRenderer<>("name", "locale")); >> } >> } >> >> with a call in my panel/fragment: >> add(new CountryDropDownChoice("country", new >> PropertyModel<String>(getDefaultModel(), "country"), getLocale())); >> >> 2. I would like to have country names depending on current user locales. >> I don't have access to Session in a model and there for I needed to pass >> current locale to both models (they call CountryService implemented as >> String bean using given locale). Could it be simplified? >> >> My files: >> >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-countrydropdownchoice-java >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-countriesmodel-java >> >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-embeddedcountrymodel-java >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-country-java >> >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-usereditpanel-java-L19 >> >> https://gist.github.com/szpak/b5c5ae36e7d170f3676c#file-javalocalecountryservice-java >> >> Thanks in advance >> Marcin -- http://blog.solidsoft.info/ - Working code is not enough --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org