Re: How to populate data from Database in combo box using DropDownChoice

2012-03-27 Thread Martin Grigorov
Hi,

DropDownChoice works with simple java.util.ListYourObject.
See 
http://www.wicket-library.com/wicket-examples/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.DropDownChoicePage
for examples.

It is up to you to read your data from the database (plain JDBC,
Hibernate, ...) and create a List of your objects.

On Tue, Mar 27, 2012 at 11:49 AM, lenin lening...@gmail.com wrote:
 Dear,

 I am trying to populate data from database in combo box using
 dropdownChoice,with key and value ...
 it is not working 
 can anyone help to resolve the problem

 thanks in advance

 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/How-to-populate-data-from-Database-in-combo-box-using-DropDownChoice-tp4508402p4508402.html
 Sent from the Users forum 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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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



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



Combo Box

2010-05-03 Thread Brian Mulholland
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
One of the greatest delusions in the world is the hope that the evils
in this world are to be cured by legislation.
--Thomas B. Reed (1886)

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