See AutoCompleteBehavior on how to response with a non-<ajax-response>.


On 04/03/2013 07:14 PM, heikki wrote:

I've a question about using AbstractDefaultAjaxBehavior. I can succesfully
create some dynamic script that calls Wicket.Ajax.get(), and its respond()
is correctly invoked. However I'm not sure what's with the results of the
ajax call, I can't get to it. It seems that I receive an empty response.

My page has a list with a number of spans that have some number for their
text; I'm trying to add an onclick to the spans that invokes the Ajax call,
passing the number of the clicked span into the Ajax URL. (This works fine.)
The Ajax response should be a (a JSON version of) the input parameterm but
it is always <ajax-response></ajax-response>.

My page has a ListView with a number of labels, like this

             <div id="myContainer" wicket:id="myContainer">
                 <div class="myUser" wicket:id="myList">
                 <div id="aResult" wicket:id="aResult" ></div>

and this JS

Then, my Page class has:

         public TestPage(final PageParameters parameters) {
             // create some numbers to display in the list
             IModel myListModel =  new LoadableDetachableModel() {
                 protected Object load() {
                     List<Integer> nrs = new ArrayList<Integer>();
                     return nrs;
             ListView myView = new ListView("myList", myListModel) {
                 protected void populateItem(ListItem item) {
                     final Integer i = (Integer) item.getModelObject();
                     item.add(new Label("myLabel", i));
             WebMarkupContainer myContainer = new

             // I expect the Ajax result to go here
             myContainer.add(new Label("aResult", "TEXT BEFORE AJAX"));

         // this reference is so I can put the URL in a js var, in
renderHead() below
         private AbstractDefaultAjaxBehavior bh ;
         private AbstractDefaultAjaxBehavior behave() {
             if(bh == null) {
                 bh = new AbstractDefaultAjaxBehavior() {
                     protected void respond(AjaxRequestTarget target) {
                         String id =
                         Gson gson = new Gson();
                         String json = gson.toJson(id);
                         System.out.println("json:\n" + json);

                         Label label = new Label("aResult",json);
                         // throws NPE
                     protected void
updateAjaxAttributes(AjaxRequestAttributes attributes) {
                         // doesn't seem to make a difference for me
             return bh;

         public void renderHead(IHeaderResponse response){
             bh = behave();
             String url = "var aUrl='" + bh.getCallbackUrl() + "';";

What I expected is that the div 'aResult' text would get replaced with the
contents of the Ajax call. It doesn't happen. And as I said the Ajax
response is empty (when viewed in Firebug).

Does anyone see what I'm missing here ?

thanks and kind regards
Heikki Doeleman

View this message in context:
Sent from the Users forum mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to