Combo Box (help!)

2010-05-06 Thread Brian Mulholland
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?

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?);
   }
});


-- 
Brian Mulholland

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



Re: Combo Box (help!)

2010-05-06 Thread Josh Glassman
[Ljava.lang.String;@HEX looks like you are stuffing an Array of Strings into
a String.  So, it calls String[].toString() and stuffs that into your
String, like so...  System.out.println(new String[] {string, array});.

I'm not real familiar with the choice renderer, so I'm not sure how this
would happen when your string gets loaded back in to your model.  Maybe
someone else has an idea?


Re: Combo Box (help!)

2010-05-06 Thread Martin Grigorov
Try with

@Override
   public String getIdValue(Object array, int arg1) {
  return Integer.toString(arg1);
   }

On Thu, 2010-05-06 at 15:44 -0400, 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?
 
 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?);
}
 });
 
 



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



Re: Combo Box (help!)

2010-05-06 Thread Thomas Kappler
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 Kapplerthomas.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