Re: Generated drop down list of countries in Wicket - any better way?
On 2013-11-20 09:28, Martin Grigorov wrote: > Hi, > > On Wed, Nov 20, 2013 at 1:30 AM, Marcin Zajączkowski wrote: > >> On 2013-11-19 08:44, Martin Grigorov wrote: >>> Hi, >>> >>> I think you can use IModel 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)? >> > > To have the locale passed to you you can use custom IConverter. > 1) DropDownChoice > 2) CountryChoiceRenderer that returns the country id for #getIdValue() and > the country name for #getDisplayValue() > 3) override DropDownChoice#getConverter (or register a global converter) > that looks up a Country by its id Thanks Martin for your explanation. Marcin >>> On Tue, Nov 19, 2013 at 12:51 AM, Marcin Zajączkowski >> 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 { public CountryDropDownChoice(String id, PropertyModel 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(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 >> >> > -- 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
Re: Generated drop down list of countries in Wicket - any better way?
Hi, On Wed, Nov 20, 2013 at 1:30 AM, Marcin Zajączkowski wrote: > On 2013-11-19 08:44, Martin Grigorov wrote: > > Hi, > > > > I think you can use IModel 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)? > To have the locale passed to you you can use custom IConverter. 1) DropDownChoice 2) CountryChoiceRenderer that returns the country id for #getIdValue() and the country name for #getDisplayValue() 3) override DropDownChoice#getConverter (or register a global converter) that looks up a Country by its id > > Marcin > > > > > On Tue, Nov 19, 2013 at 12:51 AM, Marcin Zajączkowski > 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 { > >> public CountryDropDownChoice(String id, PropertyModel > >> 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(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 > >
Re: Generated drop down list of countries in Wicket - any better way?
On 2013-11-19 08:44, Martin Grigorov wrote: > Hi, > > I think you can use IModel 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 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 { >> public CountryDropDownChoice(String id, PropertyModel >> 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(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
Re: Generated drop down list of countries in Wicket - any better way?
Hi, I think you can use IModel 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/... On Tue, Nov 19, 2013 at 12:51 AM, Marcin Zajączkowski 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 { > public CountryDropDownChoice(String id, PropertyModel > 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(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 > >
Generated drop down list of countries in Wicket - any better way?
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 { public CountryDropDownChoice(String id, PropertyModel 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(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