I would like to send ajax event from browser to wicket panel, so that it can refresh content of a label. I also need to send this request from javascript function.
Well it works - ajax request is being send, and the repose contains updated label as expected:
Ajax request:
http://localhost:8080/cyclop/cyclop/ced?1-3.IBehaviorListener.0-historyPanel&_=1392727280955
and response:
<?xml version="1.0" encoding="UTF-8"?><ajax-response><component id="idf" ><![CDATA[<div id="idf">6</div>]]></component></ajax-response>
The problem is, that I can see also another request in network monitor: it gets content of a whole page. It does not reload the page itself, just gets its content.
What is the reason for that? Is this normal?
EDIT:
I was able to investigate it a bit deeper: wicket triggers two ajax requests:
- localhost:8080/cyclop/cyclop/ced?2 - this one returns whole page
- localhost:15111/cyclop/cyclop/ced?2-11.IBehaviorListener.0-historyPanel - this one ajax response
Here is the code:
Part of HTML page containing link that triggers ajax request:
<li><div class="cq-tabHistory">MY LINK</div></li>
and java script that registers wicket callback:
$(".cq-tabHistory").on("click", function() { Wicket.Ajax.ajax({"u" : link, "c" : comp}); }
This is the wicket panel class registering ajax callback on server side
Label counter ;
public HistoryPanel(String id) {
super(id);
counter= new Label("counter", new IModel<String>() {
@Override
public String getObject() {
count++;
return count + "";
}
@Override
public void setObject(String o) {
}
@Override
public void detach() {
}
});
add(counter);
counter.setOutputMarkupId(true);
}
public void init() {
browserCallback = new AbstractDefaultAjaxBehavior() {
protected void respond(final AjaxRequestTarget target) {
target.add(counter);
}
};
add(browserCallback);
browserCallbackUrl = browserCallback.getCallbackUrl().toString();
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(OnDomReadyHeaderItem.forScript(browserCallback.getCallbackScript()));
}