0

我需要在选择 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")))

在具有 Company Object 属性的 Listview 中,选择 DropDownChoice 的 name 属性后,模型 Company 将使用选定的 Client Name 进行更新。

我怎样才能做到这一点?

谢谢

4

3 回答 3

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();
                    }
                }));
于 2013-04-09T06:35:52.370 回答
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
        }
    };
于 2013-04-09T06:29:52.873 回答
0

我认为您可以在 DropDownChoice 上使用 AjaxEventBehavior:

item.add(new DropDownChoice("clientSelection", listClients,new ChoiceRenderer[Client("name")).add(new AjaxEventBehavior("change") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            // TODO Auto-generated method stub
        }
    }))
于 2018-08-03T13:02:46.867 回答