Hi Jermey,

Thanks for your suggestion and it worked. I will remember you suggestion on
overriding equals and hashCode methods.

Just for any future reference for someone else i am putting the working
code.

public class DropDownChoicePage extends WebPage {

        public class KeyValue implements IClusterable {

                private static final long serialVersionUID = 
4901576176376580786L;

                private String key;
                private String value;

                public KeyValue(String key, String value) {
                        this.key = key;
                        this.value = value;
                }
                 // Most important to override this method 
                @Override
                public boolean equals(Object obj) {

                        KeyValue keyValueObj = (KeyValue) obj;

                        if (this == obj)
                                return true;
                        if (obj == null)
                                return false;
                        if (getClass() != obj.getClass())
                                return false;

                        if (key.toString().equals(keyValueObj.toString()))
                                return true;
                        else if 
(value.toString().equals(keyValueObj.toString()))
                                return true;

                        return false;
                }

                public String getKey() {
                        return key;
                }

                public String getValue() {
                        return value;
                }
                // Most important to override this method 
                @Override
                public int hashCode() {
                        final int prime = 31;
                        int result = 1;
                        result = prime * result + key.hashCode();
                        result = prime * result + value.hashCode();
                        return result;
                }

                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>(
                                "defaultValue", new 
PropertyModel<KeyValue>(this,
                                                "defaultValue"), keyValues,
                                new ChoiceRenderer<KeyValue>("value", "key"));
                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-tp4650704p4650708.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to