On 05/06/2010 09:44 PM, Brian Mulholland wrote:
> This is a second asking, so sorry if I am being impatient, but I was
> hoping to see a response to this.
> 
> I've got a combo box with the list in a List of string arrays (code
> and decode).  The bean has the currently selected code.  I created a
> DropDownChoice with a custom ChoceRenderer as below.  The CR interface
> is invoked for both the acquisition of the bean value and for each row
> of the list, which is why the below code checks the type of object
> coming in.
> 
> This works great when displaying, but when the value comes back to the
> server, it is loaded back into the bean as
> "[Ljava.lang.String;@3c6f3c6f".  It looks like the Object.toString().
> What am I doing wrong here?
> 

The ChoiceRenderer is only used for the display of the options on the
page, not for saving. The IModel's setObject() is called then, which in
that case is the PropertyModel calling setId() on the bean, with the
current Object as argument. So you need to implement an IModel that's a
little more intelligent and basically does what the renderer does: pick
the first element if it's an array, the whole String otherwise.

>From a design point of view it looks like this logic should maybe be in
the bean, or at least in a helper class so you can use it from both the
Model and the ChoiceRenderer.

-- Thomas


> DropDownChoice ddc = new DropDownChoice(id, new PropertyModel(bean,
> id), listOfStringArrays, new IChoiceRenderer(){
>    @Override
>    public Object getDisplayValue(Object array) {
>        if(array instanceof String)
>            return (String) array;
>        else if(array.getClass().isArray()){
>            String[] result = (String[]) array;
>            return result[1];
>        }
>        else
>            throw new RuntimeException("Huh?");
>    }
> 
>    @Override
>    public String getIdValue(Object array, int arg1) {
>        if(array instanceof String)
>            return (String) array;
>        else if(array.getClass().isArray())
>        {
>            String[] result = (String[]) array;
>            return result[0];
>        }
>        else
>            throw new RuntimeException("Huh?");
>    }
> });
> 
> 


-- 
-------------------------------------------------------------------
  Thomas Kappler                        thomas.kapp...@isb-sib.ch
  Swiss Institute of Bioinformatics         Tel: +41 22 379 51 89
  CMU, rue Michel Servet 1
  1211 Geneve 4
  Switzerland                              http://www.uniprot.org
-------------------------------------------------------------------

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

Reply via email to