1

Can anybody tell me, why this source

List<Data> datas = ~getData();
PropertyListView<Data> listView = 
new PropertyListView<Data>("listView", new PropertyModel<List<Data>>(this, "datas")){

    private static final long serialVersionUID = 1L;

    @Override
    protected void populateItem(final ListItem<Data> item) {
        Data data = item.getModelObject();
        item.add(new MultiLineLabel("textLabel", data.getText());

        @SuppressWarnings("unchecked")
        ArrayList<DataParam> params = (ArrayList<DataParam>) ~getParamsForData(data);

        DropDownChoice<DataParam> dropDownChoice = 
            new DropDownChoice<DataParam>("choiceSelector", new Model<ArrayList<DataParam>>(params), new ChoiceRenderer<Object>("key", "value")){
            private static final long serialVersionUID = 1L;

            @Override
            protected boolean wantOnSelectionChangedNotifications(){
                return true;
            }

            @Override
            protected void onSelectionChanged(DataParam newSelection) {
                super.onSelectionChanged(newSelection);
            }

        };
        item.add(dropDownChoice);                   

    }
};


public static final class DataParam implements Serializable{
    private String key;
    private String value;
    public DataParam(String key, String value){ this.key=key; this.value=value;}
    public String getKey() { return key; }
    public void setKey(String key) { this.key = key; }
    public String getValue() { return value; }
    public void setValue(String value) { this.value = value; }
}

throws this exception

WicketMessage: No get method defined for class: 
class Data expression: choiceSelector
Root cause:
org.apache.wicket.WicketRuntimeException: 
No get method defined for class: class Data expression: choiceSelector

? (so looking for get method for choiceSelector wicket component id in Data class ?!) i don't even understand

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Victor
  • 325
  • 4
  • 12

1 Answers1

5

Wicket is looking for a Model to read from and store to the selection made by the user (as well as the initially selected value).

Since you are using the DDC constructor without a model, wicket is looking in the parent of the DDC (the item) for an CompoundPropertyModel and uses the wicket:id of the DDC as expression. Hence you get the 'choiceSelectecor'.

You will either have to use an wicket:id to math the structure of your Data class or construct a DDC with a model for this.

Bert

bert
  • 7,566
  • 3
  • 31
  • 47
  • How can i construct a DDC with a model for this ? – Victor Mar 25 '12 at 21:39
  • i will check this solution 11:00 a.m. UTC/GMT +2 (it's 01:00 after midnight here :S) and after that i will value your answer, thanks very much. – Victor Mar 25 '12 at 23:03
  • @Victor: DDC has a few constructors. One of them accepts a model. – bert Mar 26 '12 at 07:08
  • it seems to working, thanks again. DropDownChoice dropDownChoice = new DropDownChoice("choiceSelector", new Model(selected), new Model>(choices), new ChoiceRenderer("key", "value")) – Victor Mar 26 '12 at 10:40