简体   繁体   English

Wicket-使用AJAX刷新组件-文档元素后出现垃圾

[英]Wicket - refresh component using AJAX - junk after document element

I'm trying to refresh the component on my page using AJAX. 我正在尝试使用AJAX刷新页面上的组件。 Here is some code: 这是一些代码:

    private class MyAjaxBehavior extends AbstractDefaultAjaxBehavior {
        private final DataView<Something> dataView;

        private MyAjaxBehavior(DataView<Something> dataView) {
            this.dataView = dataView;
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            // here I do something with dataView...
            MarkupContainer container = dataView.getParent();
            dataView.setOutputMarkupId(true);
            container.setOutputMarkupId(true);
            dataView.renderComponent();
            container.renderComponent();
            target.addComponent(container);
        }
    }

I can call respond() method using javascript functio wicketAjaxPost(<callback url>) . 我可以使用javascript wicketAjaxPost(<callback url>)来调用wicketAjaxPost(<callback url>) respond()方法。 But nothing changes on my page. 但是我的页面上没有任何变化。 When I open javascript console I see the following error: junk after document element . 当我打开javascript控制台时,看到以下错误: junk after document element出现junk after document element When I reload the page my changes are visible so this is just about AJAX. 当我重新加载页面时,我的更改是可见的,所以这只是关于AJAX的内容。 What am I doing wrong? 我究竟做错了什么? I think it's because of my invalid HTML; 我认为这是因为我的HTML无效; so how can I make user's browser ignore validation errors? 那么如何使用户的浏览器忽略验证错误?

I'm using Wicket 1.4.22. 我正在使用Wicket 1.4.22。

Do not call #renderComponent(), it will be called by wicket when it renders the container into the ajax response. 不要调用#renderComponent(),它会在将容器呈现到ajax响应中时由wicket调用。

Calling #setOutputMarkupId(true) from #respond() is too late, the components have to output their markupId before the first Ajax request. 从#respond()调用#setOutputMarkupId(true)为时已晚,组件必须在第一个Ajax请求之前输出其markupId。 You can call container#setOutputMarkupId(true) from your behavior's #onConfigure(). 您可以从行为的#onConfigure()中调用container#setOutputMarkupId(true)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM