You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sub <b4...@nwldx.com> on 2012/07/16 15:50:29 UTC

Select component and sorting order

Hi all,

I have a Country class with two-letter ISO3166 country codes, together with
a select component in a form. The problem now is the sort order of these
countries, default is the order within the enum, but that doesn't work very
well within a multi-language site. I want the sort order alphabetically
descending by the label of the countries in the corresponding property file
for the current locale. What is the recommended way to achieve this?

------------------
Country.java:
------------------
public enum Country {

	AE, /* UNITED ARAB EMIRATES */ 
	AR, /* ARGENTINA */
	AT, /* AUSTRIA */

}

------------------
Page.java:
------------------
@Property
private Country country;

------------------
Page.tml:
------------------
<t:select t:id="country" blankOption="always"/>

------------------
country.properties:
------------------
country.AE=United Arab Emirates
country.AR=Argentina
country.AT=Austria

------------------
country_de.properties:
------------------
country.AE=Vereinigte Arabische Emirate
country.AR=Argentinien
country.AT=Österreich

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Select-component-and-sorting-order-tp5714478.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Select component and sorting order

Posted by sub <b4...@nwldx.com>.
Thanks Thiago, it is working now.

Here is what I did:

------------------
Page.java:
------------------
@Property
private Country country;

@Property
@SuppressWarnings("unused")
private SelectModel countryModel;

private Country[] getSortedCountries() {
	SortedMap<String, Country> map = new TreeMap<String, Country>();
	for (Country c : Country.values()) {
	    map.put(messages.get("country."+c),c);
	}
	return map.values().toArray(new Country[map.values().size()]);
}

public void onPrepare() {
	countryModel = new EnumSelectModel(Country.class, messages,
getSortedCountries());
}



------------------
Page.tml:
------------------
<t:select t:id="country" t:model="countryModel" blankOption="always"/>

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Select-component-and-sorting-order-tp5714478p5714565.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Select component and sorting order

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 16 Jul 2012 10:50:29 -0300, sub <b4...@nwldx.com> wrote:

> Hi all,

Hi!

> I have a Country class with two-letter ISO3166 country codes, together  
> with a select component in a form. The problem now is the sort order of  
> these
> countries, default is the order within the enum, but that doesn't work  
> very well within a multi-language site. I want the sort order  
> alphabetically
> descending by the label of the countries in the corresponding property  
> file for the current locale. What is the recommended way to achieve this?

Use the model parameter of Select and provide the options in any sort  
order you want. The SelectModelFactory will probably be useful.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org