wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Grigorov <mgrigo...@apache.org>
Subject Re: Generated drop down list of countries in Wicket - any better way?
Date Tue, 19 Nov 2013 07:44:04 GMT
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/...


On Tue, Nov 19, 2013 at 12:51 AM, Marcin ZajÄ…czkowski <mszpak@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message