Hi

 

I looked at the dialog between Igor and Stefan, thought what a nice way to select the default value with the property model. However and then remembered why it did not do it that way, I wanted to replace the Choose One text with something else, well at least in some cases. Im replacing the text by overriding the getDefaultChoice method. However that doesn’t seem to work any longer(im pretty sure I had it working with wicket 1.1.1), see sniplet below? Also I noticed these lines in the documentation :

 

        // Note that when the selection is null, Wicket will lookup a localized string to
        // represent this null with key: "id + '.null'". In this case, this is 'site.null'
        // which can be found in DropDownChoicePage.properties
        form.add(new DropDownChoice("site", SITES));

Does this mean that I could write in my own version of Please Choose one in the properties file or am I reading it wrong?

 

/******Sniplet start******/

 

                                                                 dropdown = new DropDownChoice("dropdown", DropdownList.toArray()

                                                                                                             .getList(), new rowRenderer()) {

                                                                                       protected String getDefaultChoice(Object selected) {

                                                                                                             // The <option> tag buffer

                                                                                                             final StringBuffer buffer = new StringBuffer();

                                                                                                             if (isNullValid()) {

                                                                                                                                   return super.getDefaultChoice(selected);

                                                                                                             } else {

                                                                                                                                   // Null is not valid. Is it selected anyway?

                                                                                                                                   if (selected == null) {

                                                                                                                                                         // Force the user to pick a non-null value

                                                                                                                                                         final String option = dropDownInitial;

                                                                                                                                                         buffer

                                                                                                                                                                                                    .append(

                                                                                                                                                                                                                                                "\n<option selected=\"selected\" value=\"\">")

                                                                                                                                                                                                    .append(option).append("</option>");

                                                                                                                                   }

 

                                                                                                             }

                                                                                                             return buffer.toString();

                                                                                       }

 

                                                                                       protected void onSelectionChanged(Object newSelection) {

                                                                                                             fill.setEnabled(true);

                                                                                                             invoke.setEnabled(true);

                                                                                                             selectAll.setEnabled(true);

                                                                                                             deselectAll.setEnabled(true);

                                                                                                             btn_add.setEnabled(true);

                                                                                                             btn_remove.setEnabled(true);

 

                                                                                                             info("actionbutton was clicked");

                                                                                                             DataItem selected = (DataItem) dropdown.getModelObject();

                                                                                                             invoke.setChoices(DropdownList.getNewValues(

                                                                                                                                                         selected.getID()).getList());

                                                                                                             fill.setChoices(new ArrayList());

 

                                                                                       }

 

                                                                                       protected boolean wantOnSelectionChangedNotifications() {

                                                                                                             return true;

                                                                                       }

 

                                                                 };

/******Sniplet end******/

 

Regards Nino

 

Reply via email to