0

我有一个DropDownChoice带两个OnChangeAjaxBehaviors 的。当我选择应该设置为DropDownChoice禁用的值 2 时,它会在它显示我之前获得第二次禁用,AccessDeniedPage并且在服务器日志中我看到一个ListenerNotAllowedInvocationException. 在 Wicket 6 和 7 中有这个。

知道如何解决这个问题吗?

下面的代码:

选择私有整数;

public HomePage(final PageParameters parameters) {
    super(parameters);
    final DropDownChoice<Integer> ddc = new DropDownChoice<Integer>("ddc", new PropertyModel(this, "selected"), Arrays.asList(1,2,3)){
        @Override
        protected void onConfigure() {
            super.onConfigure(); 
            setEnabled(!Objects.equals(getModel().getObject(), 2));
        }

    };
    ddc.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget art) {
            art.add(getComponent()); 
            saveToDb(model.getObject);
        }
    });
    ddc.add(new OnChangeAjaxBehavior() {
        @Override
        protected void onUpdate(AjaxRequestTarget art) {
            art.add(getComponent(), otherComponent);
        }

    });
    ddc.setOutputMarkupId(true);
    add(ddc);
}

我尝试禁用与组件条件相同的行为之一,但我没有工作。

    @Override
    public boolean isEnabled(Component component) {
        return !Objects.equals(component.getDefaultModelObject(), 2);
    }

或者像这样:

    @Override
    public boolean isEnabled(Component component) {
        return component.isEnabled();
    }
4

1 回答 1

0

问题如下:

  • 第一个 Ajax 调用将模型对象更新为2并将 DropDownChoice 重新呈现为禁用
  • 然后执行第二个 Ajax 调用,并且 Wicket 阻止更新,因为该组件已禁用

为什么需要在同一个 DropDownChoice 上使用 2 个 OnChangeAjaxBehaviors ?

一种解决方案是通过对两种 Ajax 行为使用 AjaxChannel.ACTIVE 来防止此类第二次 Ajax 调用。如果此 ajax 通道上有活动的 Ajax 调用,这将告诉 Wicket JS 不执行第二个 Ajax 调用。

更新:另一种方法是覆盖 Behavior#isEnabled() 并检查是否存在名为 ddChoice#getInputName() 的请求参数,其值为 2。如果是这种情况,则返回 true,否则调用 super.isEnabled() .

于 2018-07-18T07:57:38.537 回答