简体   繁体   中英

Wicket - refresh component using AJAX - junk after document element

I'm trying to refresh the component on my page using 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>) . But nothing changes on my page. When I open javascript console I see the following error: junk after document element . When I reload the page my changes are visible so this is just about AJAX. What am I doing wrong? I think it's because of my invalid HTML; so how can I make user's browser ignore validation errors?

I'm using Wicket 1.4.22.

Do not call #renderComponent(), it will be called by wicket when it renders the container into the ajax response.

Calling #setOutputMarkupId(true) from #respond() is too late, the components have to output their markupId before the first Ajax request. You can call container#setOutputMarkupId(true) from your behavior's #onConfigure().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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