Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-10 Thread Xavier López
Hi Alex,

Expose description and id on your model's object.
>

If I understand what you're saying, this was the problem, we did want the
Component's Model to be i.e. a String, while giving the choices an
id-descr-like bean... But this is not working (must have same object type on
choices and component model), so the code above returns a List of Strings as
choices, and uses a suitable choiceRenderer in order to retrieve
descriptions from the 'description-enhanced' choice model, which consists of
a Map ...

public final static ChoiceRenderer listRenderer = new
> ChoiceRenderer("description", "id");
>

If i'm not wrong, this one will work when there is no Model object but when
there is one, it will throw out an exception, complaining it doesn't find
property 'id' nor 'description' in class String (which will be the class of
the Component's Model object)..

I don't know If i got your point though,
Thanks!
Xavier

2009/11/9 Alex Rass 

> I am a newb here, so I may be way off, but this works for me:
>
> public final static ChoiceRenderer listRenderer = new
> ChoiceRenderer("description", "id");
>
> Expose description and id on your model's object.
>
> And just add the listRenderer to the DDChoice (last param).
> Seems a lot simpler than what you are doing.
>
>
> -Original Message-
> From: Xavier López [mailto:xavil...@gmail.com]
> Sent: Monday, November 09, 2009 9:37 AM
> To: users@wicket.apache.org
> Subject: Re: Combination CompoundPropertyModel and ChoiceRenderer on
> DropDownChoice gives problems
>
> Got it!
>
> Here is the code i got into. Improvements and critics are welcome !
>
> class MappedModel extends Model {
>protected Map map;
>public String getDescription(Object id){
>return (String) map.get(id);
>}
> }
>
> // Localized choices
> final MappedModel countryModel = new MappedModel(){
>public Object getObject() {
>super.map = referenceData.getCountries(getLanguage());
>return new ArrayList(super.map.keySet());
>}
>};
>DropDownChoice ddcCountry= new
> DropDownChoice("country",countryModel);
>ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
>   public Object getDisplayValue(Object object) {
>   return countryModel.getDescription(object);
>   }
>   public String getIdValue(Object object, int index) {
>   return object.toString();
>   }
>});
>
>
> Thanks to everyone on this list not only for the heads up on this one but
> for many more I did not need to ask ;)
>
>
> 2009/11/9 Xavier López 
>
> > Hi Sven,
> >
> > Absolutely awesome. So sweet how problems vanish away when you know the
> > right way to address them on Wicket: ).
> >
> > But, what if I had a list of countries in the database (better example
> than
> > gender in this case), with its descriptions in it? Should I store a
> Country
> > entity in my bean, instead of simply and Id (taking into account this
> entity
> > possibly contains the descriptions and other unuseful stuff) ? Could I
> > manage someway, using the countryId's in the ddc's choiceList model, to
> look
> > for those descriptions in i.e. a memory-stored Map ?
> >
> > Thanks a lot!
> > Xavier
> >
> > 2009/11/9 svenmeier 
> >
> >
> >> You want to select one value from a list of values, so obviously
> >> everything
> >> has to have the same type.
> >>
> >> These 'IdDescrBeans' smell like Struts, such constructs are not needed.
> >> What's wrong with the following:
> >>
> >>  List genders = new ArrayList();
> >>  list.add("M");
> >>  list.add("F");
> >>  form.add(new DropDownChoice("gender", genders) {
> >>protected boolean localizeDisplayValues() {
> >>  return true;
> >>}
> >>  });
> >>
> >> Creating an enum would be a nice alternative to strings though.
> >> Put the following keys in you page's property file:
> >>
> >>  gender.M = male
> >>  gender.F = female
> >>
> >> i18n for free.
> >>
> >> Sven
> >>
> >>
> >> Xavier López-2 wrote:
> >> >
> >> > Hi Ann,
> >> >
> >> > I've also encountered this problem, but with RadioChoice instead of
> >> > DropDownCh

RE: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Alex Rass
I am a newb here, so I may be way off, but this works for me:

public final static ChoiceRenderer listRenderer = new
ChoiceRenderer("description", "id");

Expose description and id on your model's object.

And just add the listRenderer to the DDChoice (last param).
Seems a lot simpler than what you are doing.


-Original Message-
From: Xavier López [mailto:xavil...@gmail.com] 
Sent: Monday, November 09, 2009 9:37 AM
To: users@wicket.apache.org
Subject: Re: Combination CompoundPropertyModel and ChoiceRenderer on
DropDownChoice gives problems

Got it!

Here is the code i got into. Improvements and critics are welcome !

class MappedModel extends Model {
protected Map map;
public String getDescription(Object id){
return (String) map.get(id);
}
}

// Localized choices
final MappedModel countryModel = new MappedModel(){
public Object getObject() {
super.map = referenceData.getCountries(getLanguage());
return new ArrayList(super.map.keySet());
}
};
DropDownChoice ddcCountry= new
DropDownChoice("country",countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return countryModel.getDescription(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
});


Thanks to everyone on this list not only for the heads up on this one but
for many more I did not need to ask ;)


2009/11/9 Xavier López 

> Hi Sven,
>
> Absolutely awesome. So sweet how problems vanish away when you know the
> right way to address them on Wicket: ).
>
> But, what if I had a list of countries in the database (better example
than
> gender in this case), with its descriptions in it? Should I store a
Country
> entity in my bean, instead of simply and Id (taking into account this
entity
> possibly contains the descriptions and other unuseful stuff) ? Could I
> manage someway, using the countryId's in the ddc's choiceList model, to
look
> for those descriptions in i.e. a memory-stored Map ?
>
> Thanks a lot!
> Xavier
>
> 2009/11/9 svenmeier 
>
>
>> You want to select one value from a list of values, so obviously
>> everything
>> has to have the same type.
>>
>> These 'IdDescrBeans' smell like Struts, such constructs are not needed.
>> What's wrong with the following:
>>
>>  List genders = new ArrayList();
>>  list.add("M");
>>  list.add("F");
>>  form.add(new DropDownChoice("gender", genders) {
>>protected boolean localizeDisplayValues() {
>>  return true;
>>}
>>  });
>>
>> Creating an enum would be a nice alternative to strings though.
>> Put the following keys in you page's property file:
>>
>>  gender.M = male
>>  gender.F = female
>>
>> i18n for free.
>>
>> Sven
>>
>>
>> Xavier López-2 wrote:
>> >
>> > Hi Ann,
>> >
>> > I've also encountered this problem, but with RadioChoice instead of
>> > DropDownChoice.
>> >
>> > This is the thread I started about it:
>> >
>> >
>> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
>> >
>> > After all this thread, I still don't know what should I do to model,
for
>> > instance, a gender radioChoice which would be backed by a String
>> property
>> > ("M" of "F"), providing a list of choices (multilingual) with
>> IdDescrBeans
>> > like you propose.
>> > Should I change my bean's 'String gender' property to 'IdDescrBean
>> gender'
>> > ?
>> > Why should I store description's information on my model entity ?
>> >
>> > Although I agree with having same object's on choices and model when
>> it's
>> > about more complex data...
>> >
>> > Possible solutions I've thought of so far:
>> >
>> >- Ideally, do not use different object types in
>> compundpropertymodel's
>> >bean and choice List. Use same object type instead.
>> >- When using RadioChoice, it works if you substitute it with a
>> > RadioGroup
>> >and Radio's, using the 'id' property as the Radio's model and the
>> >'description' property as the label's model. However, when it's
about
>> >DropDownChoice, I'm clueless

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Got it!

Here is the code i got into. Improvements and critics are welcome !

class MappedModel extends Model {
protected Map map;
public String getDescription(Object id){
return (String) map.get(id);
}
}

// Localized choices
final MappedModel countryModel = new MappedModel(){
public Object getObject() {
super.map = referenceData.getCountries(getLanguage());
return new ArrayList(super.map.keySet());
}
};
DropDownChoice ddcCountry= new
DropDownChoice("country",countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return countryModel.getDescription(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
});


Thanks to everyone on this list not only for the heads up on this one but
for many more I did not need to ask ;)


2009/11/9 Xavier López 

> Hi Sven,
>
> Absolutely awesome. So sweet how problems vanish away when you know the
> right way to address them on Wicket: ).
>
> But, what if I had a list of countries in the database (better example than
> gender in this case), with its descriptions in it? Should I store a Country
> entity in my bean, instead of simply and Id (taking into account this entity
> possibly contains the descriptions and other unuseful stuff) ? Could I
> manage someway, using the countryId's in the ddc's choiceList model, to look
> for those descriptions in i.e. a memory-stored Map ?
>
> Thanks a lot!
> Xavier
>
> 2009/11/9 svenmeier 
>
>
>> You want to select one value from a list of values, so obviously
>> everything
>> has to have the same type.
>>
>> These 'IdDescrBeans' smell like Struts, such constructs are not needed.
>> What's wrong with the following:
>>
>>  List genders = new ArrayList();
>>  list.add("M");
>>  list.add("F");
>>  form.add(new DropDownChoice("gender", genders) {
>>protected boolean localizeDisplayValues() {
>>  return true;
>>}
>>  });
>>
>> Creating an enum would be a nice alternative to strings though.
>> Put the following keys in you page's property file:
>>
>>  gender.M = male
>>  gender.F = female
>>
>> i18n for free.
>>
>> Sven
>>
>>
>> Xavier López-2 wrote:
>> >
>> > Hi Ann,
>> >
>> > I've also encountered this problem, but with RadioChoice instead of
>> > DropDownChoice.
>> >
>> > This is the thread I started about it:
>> >
>> >
>> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
>> >
>> > After all this thread, I still don't know what should I do to model, for
>> > instance, a gender radioChoice which would be backed by a String
>> property
>> > ("M" of "F"), providing a list of choices (multilingual) with
>> IdDescrBeans
>> > like you propose.
>> > Should I change my bean's 'String gender' property to 'IdDescrBean
>> gender'
>> > ?
>> > Why should I store description's information on my model entity ?
>> >
>> > Although I agree with having same object's on choices and model when
>> it's
>> > about more complex data...
>> >
>> > Possible solutions I've thought of so far:
>> >
>> >- Ideally, do not use different object types in
>> compundpropertymodel's
>> >bean and choice List. Use same object type instead.
>> >- When using RadioChoice, it works if you substitute it with a
>> > RadioGroup
>> >and Radio's, using the 'id' property as the Radio's model and the
>> >'description' property as the label's model. However, when it's about
>> >DropDownChoice, I'm clueless about it at the moment (already having
>> > problems
>> >with them).
>> >- Provide a list of choices in which each element is an Id, and then
>> >provide a ChoiceRenderer display expression such that gets the proper
>> >description (I don't like that at all).
>> >- Modify IdDescrBean so that it returns the 'id' property in its
>> >'toString' method, and, assuming the compundpropertymodel's bean
>> > related
>> >property is String, provide an implementation for some useless method
>> >('trim' for example), so that it returns the desctiption. Then, in
>> the
>> >ChoiceRenderer, you can set the displayExpression to 'trim()', which
>> > will
>> >ensure that when the component model's object is a String, this error
>> > will
>> >not happen (also, it will return the trimmed id as description, but
>> > that
>> >will have no effect). But there is more to it, in order to achieve
>> >AbstractSingleSelectChoice's getModelValue() to identify the selected
>> > choice
>> >element, it calls 'indexOf' on the Choice List, using the
>> >compundpropertymodel's bean related property value. That is, it
>> > searches in
>> >a List of IdDescrBean a String. Problem is 'indexOf' invokes
>> >'searchedElement.equals(choices[i])', which will never

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Hi Ernesto, Sven,

Regarding the usage of localizeDisplayValues, I see that if I put simply "M"
or "F" it also works. Wonderful! Now I can define a general description for
"M" and "F", and provide specialized ones in case of need (thinking about
yes/no literals). But, could I someway define 'groups' of yes/no
descriptions (i.e. yes/no, positive/negative) and tell someway the component
to look for one or antoher having only the "Y", "N" literals? (maybe out of
scope on this question)


Why not use IChoiceRenderer?
>

I suppose you mean anonimously subclassing ChoiceRenderer and overriding
getDisplayValue in order to get the proper description... Something like
what Pedro proposed here maybe?
http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/%3c341aa5500911040801j3f2cb9e0tc1109314522d5...@mail.gmail.com%3e

That could be good, although maybe pulling out the description for each
choice could penalize performance...

Igor also proposed a solution to another problem that might come in handy in
http://www.mail-archive.com/wicket-u...@lists.sourceforge.net/msg26881.html

I'd like to do something like this:

// Localized choices
final Model countryModel = new Model(){
public Object getObject() {
return referenceData.getCountries(getLanguage());
}
};
DropDownChoice ddcCountry = new DropDownChoice("country",countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return ((Map)countryModel.getObject()).get(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
};

Only that countryModel's getObject should return a List instead of a Map
(and I'd like the model to be dynamic)

Thanks a lot!
Xavier


2009/11/9 Ernesto Reinaldo Barreiro 

> Why not use IChoiceRenderer?
>
> Ernesto
>
> On Mon, Nov 9, 2009 at 2:27 PM, Xavier López  wrote:
>
> > Hi Sven,
> >
> > Absolutely awesome. So sweet how problems vanish away when you know the
> > right way to address them on Wicket: ).
> >
> > But, what if I had a list of countries in the database (better example
> than
> > gender in this case), with its descriptions in it? Should I store a
> Country
> > entity in my bean, instead of simply and Id (taking into account this
> > entity
> > possibly contains the descriptions and other unuseful stuff) ? Could I
> > manage someway, using the countryId's in the ddc's choiceList model, to
> > look
> > for those descriptions in i.e. a memory-stored Map ?
> >
> > Thanks a lot!
> > Xavier
> >
> > 2009/11/9 svenmeier 
> >
> > >
> > > You want to select one value from a list of values, so obviously
> > everything
> > > has to have the same type.
> > >
> > > These 'IdDescrBeans' smell like Struts, such constructs are not needed.
> > > What's wrong with the following:
> > >
> > >  List genders = new ArrayList();
> > >  list.add("M");
> > >  list.add("F");
> > >  form.add(new DropDownChoice("gender", genders) {
> > >protected boolean localizeDisplayValues() {
> > >  return true;
> > >}
> > >  });
> > >
> > > Creating an enum would be a nice alternative to strings though.
> > > Put the following keys in you page's property file:
> > >
> > >  gender.M = male
> > >  gender.F = female
> > >
> > > i18n for free.
> > >
> > > Sven
> > >
> > >
> > > Xavier López-2 wrote:
> > > >
> > > > Hi Ann,
> > > >
> > > > I've also encountered this problem, but with RadioChoice instead of
> > > > DropDownChoice.
> > > >
> > > > This is the thread I started about it:
> > > >
> > > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
> > > >
> > > > After all this thread, I still don't know what should I do to model,
> > for
> > > > instance, a gender radioChoice which would be backed by a String
> > property
> > > > ("M" of "F"), providing a list of choices (multilingual) with
> > > IdDescrBeans
> > > > like you propose.
> > > > Should I change my bean's 'String gender' property to 'IdDescrBean
> > > gender'
> > > > ?
> > > > Why should I store description's information on my model entity ?
> > > >
> > > > Although I agree with having same object's on choices and model when
> > it's
> > > > about more complex data...
> > > >
> > > > Possible solutions I've thought of so far:
> > > >
> > > >- Ideally, do not use different object types in
> > compundpropertymodel's
> > > >bean and choice List. Use same object type instead.
> > > >- When using RadioChoice, it works if you substitute it with a
> > > > RadioGroup
> > > >and Radio's, using the 'id' property as the Radio's model and the
> > > >'description' property as the label's model. However, when it's
> > about
> > > >DropDownChoice, I'm clueless about it at the moment (already
> having
> > > > problems
> > > >with them).
> > > >- Provide a list of choices in which each element is an Id, and
> then
> > > >provide a Cho

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Ernesto Reinaldo Barreiro
Why not use IChoiceRenderer?

Ernesto

On Mon, Nov 9, 2009 at 2:27 PM, Xavier López  wrote:

> Hi Sven,
>
> Absolutely awesome. So sweet how problems vanish away when you know the
> right way to address them on Wicket: ).
>
> But, what if I had a list of countries in the database (better example than
> gender in this case), with its descriptions in it? Should I store a Country
> entity in my bean, instead of simply and Id (taking into account this
> entity
> possibly contains the descriptions and other unuseful stuff) ? Could I
> manage someway, using the countryId's in the ddc's choiceList model, to
> look
> for those descriptions in i.e. a memory-stored Map ?
>
> Thanks a lot!
> Xavier
>
> 2009/11/9 svenmeier 
>
> >
> > You want to select one value from a list of values, so obviously
> everything
> > has to have the same type.
> >
> > These 'IdDescrBeans' smell like Struts, such constructs are not needed.
> > What's wrong with the following:
> >
> >  List genders = new ArrayList();
> >  list.add("M");
> >  list.add("F");
> >  form.add(new DropDownChoice("gender", genders) {
> >protected boolean localizeDisplayValues() {
> >  return true;
> >}
> >  });
> >
> > Creating an enum would be a nice alternative to strings though.
> > Put the following keys in you page's property file:
> >
> >  gender.M = male
> >  gender.F = female
> >
> > i18n for free.
> >
> > Sven
> >
> >
> > Xavier López-2 wrote:
> > >
> > > Hi Ann,
> > >
> > > I've also encountered this problem, but with RadioChoice instead of
> > > DropDownChoice.
> > >
> > > This is the thread I started about it:
> > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
> > >
> > > After all this thread, I still don't know what should I do to model,
> for
> > > instance, a gender radioChoice which would be backed by a String
> property
> > > ("M" of "F"), providing a list of choices (multilingual) with
> > IdDescrBeans
> > > like you propose.
> > > Should I change my bean's 'String gender' property to 'IdDescrBean
> > gender'
> > > ?
> > > Why should I store description's information on my model entity ?
> > >
> > > Although I agree with having same object's on choices and model when
> it's
> > > about more complex data...
> > >
> > > Possible solutions I've thought of so far:
> > >
> > >- Ideally, do not use different object types in
> compundpropertymodel's
> > >bean and choice List. Use same object type instead.
> > >- When using RadioChoice, it works if you substitute it with a
> > > RadioGroup
> > >and Radio's, using the 'id' property as the Radio's model and the
> > >'description' property as the label's model. However, when it's
> about
> > >DropDownChoice, I'm clueless about it at the moment (already having
> > > problems
> > >with them).
> > >- Provide a list of choices in which each element is an Id, and then
> > >provide a ChoiceRenderer display expression such that gets the
> proper
> > >description (I don't like that at all).
> > >- Modify IdDescrBean so that it returns the 'id' property in its
> > >'toString' method, and, assuming the compundpropertymodel's bean
> > > related
> > >property is String, provide an implementation for some useless
> method
> > >('trim' for example), so that it returns the desctiption. Then, in
> the
> > >ChoiceRenderer, you can set the displayExpression to 'trim()', which
> > > will
> > >ensure that when the component model's object is a String, this
> error
> > > will
> > >not happen (also, it will return the trimmed id as description, but
> > > that
> > >will have no effect). But there is more to it, in order to achieve
> > >AbstractSingleSelectChoice's getModelValue() to identify the
> selected
> > > choice
> > >element, it calls 'indexOf' on the Choice List, using the
> > >compundpropertymodel's bean related property value. That is, it
> > > searches in
> > >a List of IdDescrBean a String. Problem is 'indexOf' invokes
> > >'searchedElement.equals(choices[i])', which will never return true.
> I
> > > got it
> > >to work overriding 'getModelObject' and doing this search with the
> > > opposite
> > >comparation (choices[i].equals(searchedElement), and providing a
> > > suitable
> > >implementation of 'equals' in the IdDescrBean class... But that's
> > > extremely
> > >hacky and ugly, and... it would not work for ListMultipleChoice, as
> > >getModelValue is final...
> > >
> > >
> > >
> > > 2009/11/9 Ann Baert 
> > >
> > >> I've created a jira issue with more information and an example for
> this
> > >> problem:
> > >> https://issues.apache.org/jira/browse/WICKET-2565
> > >>  DISCLAIMER 
> > >>
> > >> http://www.tvh.com/newen2/emaildisclaimer/default.html
> > >>
> > >> "This message is delivered to all addressees subject to the conditions
> > >> set forth in the attached disclaimer, which is an integral part of
> this
> > >> message."
> > >>
> > >
> >

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Hi Sven,

Absolutely awesome. So sweet how problems vanish away when you know the
right way to address them on Wicket: ).

But, what if I had a list of countries in the database (better example than
gender in this case), with its descriptions in it? Should I store a Country
entity in my bean, instead of simply and Id (taking into account this entity
possibly contains the descriptions and other unuseful stuff) ? Could I
manage someway, using the countryId's in the ddc's choiceList model, to look
for those descriptions in i.e. a memory-stored Map ?

Thanks a lot!
Xavier

2009/11/9 svenmeier 

>
> You want to select one value from a list of values, so obviously everything
> has to have the same type.
>
> These 'IdDescrBeans' smell like Struts, such constructs are not needed.
> What's wrong with the following:
>
>  List genders = new ArrayList();
>  list.add("M");
>  list.add("F");
>  form.add(new DropDownChoice("gender", genders) {
>protected boolean localizeDisplayValues() {
>  return true;
>}
>  });
>
> Creating an enum would be a nice alternative to strings though.
> Put the following keys in you page's property file:
>
>  gender.M = male
>  gender.F = female
>
> i18n for free.
>
> Sven
>
>
> Xavier López-2 wrote:
> >
> > Hi Ann,
> >
> > I've also encountered this problem, but with RadioChoice instead of
> > DropDownChoice.
> >
> > This is the thread I started about it:
> >
> >
> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
> >
> > After all this thread, I still don't know what should I do to model, for
> > instance, a gender radioChoice which would be backed by a String property
> > ("M" of "F"), providing a list of choices (multilingual) with
> IdDescrBeans
> > like you propose.
> > Should I change my bean's 'String gender' property to 'IdDescrBean
> gender'
> > ?
> > Why should I store description's information on my model entity ?
> >
> > Although I agree with having same object's on choices and model when it's
> > about more complex data...
> >
> > Possible solutions I've thought of so far:
> >
> >- Ideally, do not use different object types in compundpropertymodel's
> >bean and choice List. Use same object type instead.
> >- When using RadioChoice, it works if you substitute it with a
> > RadioGroup
> >and Radio's, using the 'id' property as the Radio's model and the
> >'description' property as the label's model. However, when it's about
> >DropDownChoice, I'm clueless about it at the moment (already having
> > problems
> >with them).
> >- Provide a list of choices in which each element is an Id, and then
> >provide a ChoiceRenderer display expression such that gets the proper
> >description (I don't like that at all).
> >- Modify IdDescrBean so that it returns the 'id' property in its
> >'toString' method, and, assuming the compundpropertymodel's bean
> > related
> >property is String, provide an implementation for some useless method
> >('trim' for example), so that it returns the desctiption. Then, in the
> >ChoiceRenderer, you can set the displayExpression to 'trim()', which
> > will
> >ensure that when the component model's object is a String, this error
> > will
> >not happen (also, it will return the trimmed id as description, but
> > that
> >will have no effect). But there is more to it, in order to achieve
> >AbstractSingleSelectChoice's getModelValue() to identify the selected
> > choice
> >element, it calls 'indexOf' on the Choice List, using the
> >compundpropertymodel's bean related property value. That is, it
> > searches in
> >a List of IdDescrBean a String. Problem is 'indexOf' invokes
> >'searchedElement.equals(choices[i])', which will never return true. I
> > got it
> >to work overriding 'getModelObject' and doing this search with the
> > opposite
> >comparation (choices[i].equals(searchedElement), and providing a
> > suitable
> >implementation of 'equals' in the IdDescrBean class... But that's
> > extremely
> >hacky and ugly, and... it would not work for ListMultipleChoice, as
> >getModelValue is final...
> >
> >
> >
> > 2009/11/9 Ann Baert 
> >
> >> I've created a jira issue with more information and an example for this
> >> problem:
> >> https://issues.apache.org/jira/browse/WICKET-2565
> >>  DISCLAIMER 
> >>
> >> http://www.tvh.com/newen2/emaildisclaimer/default.html
> >>
> >> "This message is delivered to all addressees subject to the conditions
> >> set forth in the attached disclaimer, which is an integral part of this
> >> message."
> >>
> >
> >
> >
> > --
> > "To err is human; to make real mess, you need a computer."
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Combination-CompoundPropertyModel-and-ChoiceRenderer-on-DropDownChoice-gives-problems-tp26262235p26266089.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> -

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread svenmeier

You want to select one value from a list of values, so obviously everything
has to have the same type.

These 'IdDescrBeans' smell like Struts, such constructs are not needed.
What's wrong with the following:

  List genders = new ArrayList();
  list.add("M");
  list.add("F");
  form.add(new DropDownChoice("gender", genders) {
protected boolean localizeDisplayValues() {
  return true;
}
  });

Creating an enum would be a nice alternative to strings though.
Put the following keys in you page's property file:

  gender.M = male
  gender.F = female

i18n for free.

Sven


Xavier López-2 wrote:
> 
> Hi Ann,
> 
> I've also encountered this problem, but with RadioChoice instead of
> DropDownChoice.
> 
> This is the thread I started about it:
> 
> http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
> 
> After all this thread, I still don't know what should I do to model, for
> instance, a gender radioChoice which would be backed by a String property
> ("M" of "F"), providing a list of choices (multilingual) with IdDescrBeans
> like you propose.
> Should I change my bean's 'String gender' property to 'IdDescrBean gender'
> ?
> Why should I store description's information on my model entity ?
> 
> Although I agree with having same object's on choices and model when it's
> about more complex data...
> 
> Possible solutions I've thought of so far:
> 
>- Ideally, do not use different object types in compundpropertymodel's
>bean and choice List. Use same object type instead.
>- When using RadioChoice, it works if you substitute it with a
> RadioGroup
>and Radio's, using the 'id' property as the Radio's model and the
>'description' property as the label's model. However, when it's about
>DropDownChoice, I'm clueless about it at the moment (already having
> problems
>with them).
>- Provide a list of choices in which each element is an Id, and then
>provide a ChoiceRenderer display expression such that gets the proper
>description (I don't like that at all).
>- Modify IdDescrBean so that it returns the 'id' property in its
>'toString' method, and, assuming the compundpropertymodel's bean
> related
>property is String, provide an implementation for some useless method
>('trim' for example), so that it returns the desctiption. Then, in the
>ChoiceRenderer, you can set the displayExpression to 'trim()', which
> will
>ensure that when the component model's object is a String, this error
> will
>not happen (also, it will return the trimmed id as description, but
> that
>will have no effect). But there is more to it, in order to achieve
>AbstractSingleSelectChoice's getModelValue() to identify the selected
> choice
>element, it calls 'indexOf' on the Choice List, using the
>compundpropertymodel's bean related property value. That is, it
> searches in
>a List of IdDescrBean a String. Problem is 'indexOf' invokes
>'searchedElement.equals(choices[i])', which will never return true. I
> got it
>to work overriding 'getModelObject' and doing this search with the
> opposite
>comparation (choices[i].equals(searchedElement), and providing a
> suitable
>implementation of 'equals' in the IdDescrBean class... But that's
> extremely
>hacky and ugly, and... it would not work for ListMultipleChoice, as
>getModelValue is final...
> 
> 
> 
> 2009/11/9 Ann Baert 
> 
>> I've created a jira issue with more information and an example for this
>> problem:
>> https://issues.apache.org/jira/browse/WICKET-2565
>>  DISCLAIMER 
>>
>> http://www.tvh.com/newen2/emaildisclaimer/default.html
>>
>> "This message is delivered to all addressees subject to the conditions
>> set forth in the attached disclaimer, which is an integral part of this
>> message."
>>
> 
> 
> 
> -- 
> "To err is human; to make real mess, you need a computer."
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Combination-CompoundPropertyModel-and-ChoiceRenderer-on-DropDownChoice-gives-problems-tp26262235p26266089.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Hi Ann,

I've also encountered this problem, but with RadioChoice instead of
DropDownChoice.

This is the thread I started about it:

http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser

After all this thread, I still don't know what should I do to model, for
instance, a gender radioChoice which would be backed by a String property
("M" of "F"), providing a list of choices (multilingual) with IdDescrBeans
like you propose.
Should I change my bean's 'String gender' property to 'IdDescrBean gender' ?
Why should I store description's information on my model entity ?

Although I agree with having same object's on choices and model when it's
about more complex data...

Possible solutions I've thought of so far:

   - Ideally, do not use different object types in compundpropertymodel's
   bean and choice List. Use same object type instead.
   - When using RadioChoice, it works if you substitute it with a RadioGroup
   and Radio's, using the 'id' property as the Radio's model and the
   'description' property as the label's model. However, when it's about
   DropDownChoice, I'm clueless about it at the moment (already having problems
   with them).
   - Provide a list of choices in which each element is an Id, and then
   provide a ChoiceRenderer display expression such that gets the proper
   description (I don't like that at all).
   - Modify IdDescrBean so that it returns the 'id' property in its
   'toString' method, and, assuming the compundpropertymodel's bean related
   property is String, provide an implementation for some useless method
   ('trim' for example), so that it returns the desctiption. Then, in the
   ChoiceRenderer, you can set the displayExpression to 'trim()', which will
   ensure that when the component model's object is a String, this error will
   not happen (also, it will return the trimmed id as description, but that
   will have no effect). But there is more to it, in order to achieve
   AbstractSingleSelectChoice's getModelValue() to identify the selected choice
   element, it calls 'indexOf' on the Choice List, using the
   compundpropertymodel's bean related property value. That is, it searches in
   a List of IdDescrBean a String. Problem is 'indexOf' invokes
   'searchedElement.equals(choices[i])', which will never return true. I got it
   to work overriding 'getModelObject' and doing this search with the opposite
   comparation (choices[i].equals(searchedElement), and providing a suitable
   implementation of 'equals' in the IdDescrBean class... But that's extremely
   hacky and ugly, and... it would not work for ListMultipleChoice, as
   getModelValue is final...



2009/11/9 Ann Baert 

> I've created a jira issue with more information and an example for this
> problem:
> https://issues.apache.org/jira/browse/WICKET-2565
>  DISCLAIMER 
>
> http://www.tvh.com/newen2/emaildisclaimer/default.html
>
> "This message is delivered to all addressees subject to the conditions
> set forth in the attached disclaimer, which is an integral part of this
> message."
>



-- 
"To err is human; to make real mess, you need a computer."