Very instructive. I made one change in order to use the properties file for
that Enum class instead of this specific component and everything works fine
now. Thanks a lot.

        protected IModel createLabelModel( IModel itemModel ) {
                final IModel property = super.createLabelModel( itemModel );
                return new AbstractReadOnlyModel() {
                        public Object getObject(Component component) {
                                String key = ((Enum)property.getObject( 
component )).name();
//                                              String s = component.getString( 
key );
                                                String s = 
resourceLoader.loadStringResource( null, key,
Session.get().getLocale(), Session.get().getStyle());
                                return s;
                        }
                        public void detach() {
                                property.detach();
                        }                                                       
        
                };                                                      
        }



igor.vaynberg wrote:
> 
> something like this:
> 
> new ChoiceFilteredPropertyColumn(....) {
>     IModel createLabelModel(IModel itemModel) {
>            final IModel property=super.createLabelModel(itemModel);
>            return new AbstractReadOnlyModel() {
>                  Object getObject(Component c) {
>                         // will localize the enum
>                         
> c.getString(((Enum)property.getObject(c)).name());
>                   }
>                   void ondetach() { property.detach(); }
>              }
>    }
> }
> 
> 
> -Igor
> 
> 
> On 7/24/06, Wilko Hische <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hi,
>>
>> My apologies if the following is simple, but I am relatively new to
>> Wicket (moving from Tapestry),  and wasn't  able to figure out an
>> elegant solution:
>>
>> I would like to add an Enum property to the Contact class of the
>> wicket-phonebook application, say a Gender:
>>
>> public enum Gender {
>>     MALE,
>>     FEMALE
>> }
>>
>> class Contact {
>>     private Gender gender;
>>     ...
>>     // getter and setter
>> }
>>
>> The contact's gender should be shown as another
>> ChoiceFilteredPropertyColumn of the DefaultDataTable on the ListContacts
>> page.
>> So far no problem.
>>
>> Now I would like to localise the Gender type with a Gender.properties
>> file on the Gender's class path.
>> This properties file would then be used for
>> 1. the columns filter selection
>> 2. the contact's gender field
>> 3. the Gender column's row values.
>>
>> This last one I could not figure out. I guess I am looking for a way to
>> have the StringResourceModel  use  a ClassResourceLoader for the Gender
>> class, but it does not seem to allow for this.
>>
>> In the end I got it something working that makes use of keys in my
>> application.properties (Gender.MALE, Gender.FEMALE) but I would prefer a
>> separate properties file.
>>
>> Best regards,
>>
>> Wilko Hische
>>
> 
> 
-- 
View this message in context: 
http://www.nabble.com/Localisation-of-Enum-properties-%28Newbie-question%29-tf1992377.html#a5470203
Sent from the Wicket - User forum at Nabble.com.


-------------------------------------------------------------------------
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