Wicket使用ajax对URL进行奇怪的行为

时间:2016-10-11 22:08:33

标签: javascript ajax wicket wicket-7

我有一些奇怪的步骤。我在头部渲染阶段呈现了ajax行为

    final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
       protected void respond(final AjaxRequestTarget target) {
             boolean undoEn = getRequest().getQueryParameters().getParameterValue("undoEn").toBoolean();
             if (undoEn) {
                mSaveButton.setEnabled(true);
                target.add(mSaveButton);
             }
        }
    };

    public String getCallbackName() {
        return "saveButtonVisibilityToggle";
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        String script = getCallbackName() + " = function (e) {  Wicket.Ajax.ajax({\"u\": \"" + behave.getCallbackUrl() + " + &undoEn=\"+e+\"\" });}";
        response.render(OnDomReadyHeaderItem.forScript(script));
    }

这一切都运行良好,每次在tinyMCE编辑器中更改节点时都会调用此行为

     settings.addCustomSetting(" setup: function(editor) {" +
            "        editor.on('NodeChange', function(e) {" +
            " editor.save();" +
            getCallbackName() + "(editor.undoManager.hasUndo())" +
            "        });" +
            "    }");

但有时当我离开浏览器标签时,更改几个标签(chrome)然后使用其他应用程序几分钟,然后转回我们的标签,ajax网址意外出现在浏览器网址中。

http://localhost:8080/wicket/bookmarkable/com.tac.kulik.pages.SomePage?3-1.IBehaviorListener.0-contentPanel&entityId=2+++&undoEn=true

这也很奇怪,相反,normap参数传递了它的++++符号

顺便说一句,这个叹息被认为是“2”,所以出于某种原因'+'变成了空白

更新1  使用@svenmeier回答我的页面启动无限循环刷新。与日志

org.apache.wicket.core.request.mapper.StalePageException: A request to     
page '[Page class = x.x.x.CardPage, id = 25, render count = 1]' has been
 made with stale 'renderCount'. The page will be re-rendered.

并且由于某种原因,表现为链接有renderCount 1,但表单有0。 来自浏览器的请求     jquery-1.12.4-ver-1476216952000.js:10254 XHR完成加载:GET“http://localhost:8080/wicket/bookmarkable/com.tac.pages.ca ...?4-0.IBehaviorListener.0-contentPanel& cardId = 1& _ = 1476873175645& undoEn = true”

我添加了一些JS以防止cicling刷新,但我仍然有Stale异常

     "if (editor.undoManager.hasUndo()) { " +
            "                  console.debug('Behave called ');" +
            behave.getCallbackScript() +
            "        }" +

这是我的举止

   final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
        protected void respond(final AjaxRequestTarget target) {
            log.info("Behave called");
            boolean undoEn = getRequest().getQueryParameters().getParameterValue("undoEn").toBoolean();
            if (undoEn) {
                mSaveButton.setEnabled(true);
                target.add(mSaveButton);
            }
        }
        //
        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            String undoEn = "return {'undoEn': editor.undoManager.hasUndo()};";
            attributes.getDynamicExtraParameters().add(undoEn);
        }
    };

并没有区别,它可以表现得没有任何实现,页面行为相同((

    final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
        @Override
        protected void respond(AjaxRequestTarget target) {

        }
    };

1 个答案:

答案 0 :(得分:2)

您应该重新设计行为以使用动态额外参数。

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
    super.updateAjaxAttributes(attributes);

    String undoEn = "return {'undoEn': editor.undoManager.hasUndo()}";
    attributes.getDynamicExtraParameters().add(undoEn);
}

settings.addCustomSetting(
        "setup: function(editor) {" +
        "  editor.on('NodeChange', function(e) {" +
        "    editor.save();" +
        "    " + getCallbackScript() + ";" +
        "  });" +
        "}");