coolguy
coolguy

Reputation: 3071

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 functiowicketAjaxPost(<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.

Upvotes: 0

Views: 784

Answers (1)

svenmeier
svenmeier

Reputation: 5681

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().

Upvotes: 3

Related Questions