Wicket:DropDownChoice项目选择事件的更新模型

Ber*_*era 0 java wicket scala

我需要在选择DropDownChoice项后立即更新模型或对象.

贝娄是我正在工作的代码:

add(new ListView[Company]("listCompanies", listData) {

    override protected def onBeforeRender() {
      //
      // ...
      super.onBeforeRender()
    }

    def populateItem(item: ListItem[Company]) = {
      var company = item.getModelObject()

      //...

      val listClients: java.util.List[Client] = clientControler.listClients


      item.add(new DropDownChoice("clientSelection", listClients,new ChoiceRenderer[Client]("name")))
Run Code Online (Sandbox Code Playgroud)

在具有Company Object属性的Listview中,在选择DropDownChoice的name属性后,将更新模型Company并选择Client Name.

我怎样才能做到这一点?

谢谢

cre*_*ea1 7

我认为你可以覆盖onSelectionChanged.但是你还需要覆盖wantOnSelectionChangedNotifications以返回true以使其工作.像这样的东西.

    DropDownChoice<Client> dropDownChoice = new DropDownChoice("clientSelection", listClients) {
        @Override
        protected boolean wantOnSelectionChangedNotifications() {
            return true;
        }

        @Override
        protected void onSelectionChanged(Object newSelection) {
            // Do something here when selection is changed
        }
    };
Run Code Online (Sandbox Code Playgroud)


hud*_*udi 7

您需要添加更新行为:

    add(new DropDownChoice<Client>("clientSelection", listClients)
                .add(new AjaxFormComponentUpdatingBehavior("onchange") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    protected void onUpdate(AjaxRequestTarget target) {

// update your model here
// then you need to add model to target
                        target.add();
                    }
                }));
Run Code Online (Sandbox Code Playgroud)