Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the Wicket DropDownChoice how can you replace "Choose one" to another text

I have a DropDownChoice like below:

    final DropDownChoice<Term> terms = new DropDownChoice("terms", new Model<Term>(), new Model(new ArrayList(termDao.findAll())), new IChoiceRenderer<Term>() {
        public Object getDisplayValue(Term object) {
            return object.getIdentifier();
        }

        public String getIdValue(Term object, int index) {
            return object.getId().toString();
        }
    });

I want to have "Choose All" instead of "Choose one". How can I do that?

like image 663
Gollie Avatar asked Jan 09 '12 11:01

Gollie


3 Answers

I tried Goli's suggestion under wicket 6.4 and it doesn't work. For me the right way is:

  1. It is not necessary to set terms.setMarkupId("termsDDC"); It will work without it

  2. Exactly as above, if you have a form on the panel (wicket:id="form") and a DropDownChoice on the form (wicket:id="terms"), it doesn't matter, you should name .properties file as mypanel.properties

  3. In the property file write: form.terms.null=Choose All or form.terms.nullValid=Empty, if the dropdown has setNullValid(true)

like image 162
user2565039 Avatar answered Jan 04 '23 11:01

user2565039


  1. Set a markup id for your DropDownChoice.: terms.setMarkupId("termsDDC");

  2. Create a .properties file for your form/panel/page. For example: mypanel.properties

  3. In the property file write: termsDDC.null=Choose All

Ref: https://cwiki.apache.org/WICKET/dropdownchoice.html

like image 32
Gollie Avatar answered Jan 04 '23 12:01

Gollie


I'm using wicket 6.14 (not sure which version it was introduced) and you can just override getNullKeyDisplayValue(), so you would have this:

final DropDownChoice<Term> terms = new DropDownChoice("terms", new Model<Term>(), new Model(new ArrayList(termDao.findAll())), new IChoiceRenderer<Term>() {
    @Override
    protected String getNullKeyDisplayValue() {
        return "Choose All";
    }

    public Object getDisplayValue(Term object) {
        return object.getIdentifier();
    }

    public String getIdValue(Term object, int index) {
        return object.getId().toString();
    }
});
like image 25
Andy Avatar answered Jan 04 '23 12:01

Andy