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<String> genders = new ArrayList<String>();
  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 <ann.ba...@tvh.be>
> 
>> 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

Reply via email to