DropDownChoice Default Value

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

DropDownChoice Default Value

vimalsymbi
This post has NOT been accepted by the mailing list yet.
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.