On Sun, Jul 22, 2012 at 3:52 PM, vimalsymbi <vimal_sy...@yahoo.com> wrote:

> Hi All,
>
> I have searched and wasted much of my time figuring out the default Value
> for DropDownChoice for Object as dropdown but couldn't find the solution.
> For "String" dropdown i was able to make it work but somehow for object it
> is not working.
>
> Below is the Simple example that i have been trying,
> DropDownChoicePage.html
> and DropDownChoicePage.java files.
>
> Can someone please help me that what am i missing into
> "DropDownChoicePage.java" class that is not setting the Drop Down Default
> value?
>
> ----------------------------------------
>
> DropDownChoicePage.html
>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head>
>     <title>DropDown Example</title>
> </head>
> <body>
>
> Select your favorite Language               <select
> wicket:id="languageDropDown"></select>
>
> </body>
> </html>
>
> ---------------------------------------------------------------
>
> DropDownChoicePage.java
>
> public class DropDownChoicePage extends WebPage {
>
>         public class KeyValue {
>
>                 private String key;
>                 private String value;
>
>                 public KeyValue(String key, String value) {
>                         this.key = key;
>                         this.value = value;
>                 }
>
>                 public String getKey() {
>                         return key;
>                 }
>
>                 public String getValue() {
>                         return value;
>                 }
>
>                 public void setKey(String key) {
>                         this.key = key;
>                 }
>
>                 public void setValue(String value) {
>                         this.value = value;
>                 }
>
>                 @Override
>                 public String toString() {
>                         return getKey();
>                 }
>         }
>
>         private static final long serialVersionUID = 2304448232406333188L;
>
>         private KeyValue defaultValue = new KeyValue("JAVA", "Java");
>
>         /**
>          * Constructor
>          */
>         public DropDownChoicePage() {
>
>                 List<KeyValue> keyValues = new
> ArrayList<DropDownChoicePage.KeyValue>();
>                 keyValues.add(new KeyValue("PHP", "php"));
>                 keyValues.add(new KeyValue("JAVA", "Java"));
>                 keyValues.add(new KeyValue("DOT_NET", "Dot Net"));
>
>                 DropDownChoice<KeyValue> dropDownChoice = new
> DropDownChoice<KeyValue>(
>                                 "languageDropDown", new
> PropertyModel<KeyValue>(this,
>                                                 "defaultValue"), keyValues,
>                                 new ChoiceRenderer<KeyValue>("key",
> "value"));
>                 add(dropDownChoice);
>
>         }
>
>         public KeyValue getDefaultValue() {
>                 return defaultValue;
>         }
>
>         public void setDefaultValue(KeyValue defaultValue) {
>                 this.defaultValue = defaultValue;
>         }
>
> }
>
> Thanks,
> Vimal.
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/DropDownChoice-Default-Value-tp4650704.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
>
>
If I had to guess I'd guess it's because your KeyValuePair class does not
properly implement either equals or hashCode.  As I say many times during
my classes: don't get so distracted with "how do I do this in Wicket" that
you forget that this is "just java".

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Reply via email to