I'm currently using wicket 1.5.1, testing with Firefox (latest).

 

When wicket receives an ajax GET request it seems to store the query
parameters of the last such request, and append them to the base url
upon page reload. I'm sure this behavior serves a very valid purpose,
but I'm wrapping a javascript-based component with a server side wicket
component, and the result is messing me up. To be specific, I have a
javascript select-like component which stores its current selection
choice in a value field, and I'm adding javascript via the renderHead()
method of the wicket wrapper to return that value via wicket ajax get.
I'm also sending whether this is an initial contact or a subsequent
selection. The render head method looks like...

 

  @Override

  public void renderHead (IHeaderResponse response) {

 

    response.renderJavaScript("var " + getWatchFunctionName() + " =
function(){dijit.byId('" + select.getMarkupId() + "').watch('value',
function(name, oldValue, newValue){" +
valueChangedBehavior.getCallbackScript(false) +
"})};dojo.addOnLoad(function() {" +
valueChangedBehavior.getCallbackScript(true) + "});dojo.addOnLoad(" +
getWatchFunctionName() + ");", DojoSelect.class.getName() + ".watch." +
select.getMarkupId());

  }

 

As you can see it's a dojo select component, and I'm using dojo's
watch() function to call back to a behavior on the wicket wrapper...

 

  private class SelectValueChangedBehavior extends
AbstractDefaultAjaxBehavior {

 

    private CharSequence getCallbackScript (boolean initial) {

 

      return generateCallbackScript("wicketAjaxGet('" +
getCallbackUrl(initial) + "'");

    }

 

    private CharSequence getCallbackUrl (boolean initial) {

 

      return super.getCallbackUrl() + "&" + select.getMarkupId() +
".value='+ dijit.byId('" + select.getMarkupId() + "').value + '&" +
select.getMarkupId() + ".initial=" + initial;

    }

 

    @Override

    protected synchronized void respond (AjaxRequestTarget target) {

 

      boolean initial =
Boolean.parseBoolean(RequestCycle.get().getRequest().getQueryParameters(
).getParameterValue(select.getMarkupId() + ".initial").toString());

 

 
setValue(RequestCycle.get().getRequest().getQueryParameters().getParamet
erValue(select.getMarkupId() + ".value").toString(), initial);

 

      if (!initial) {

        for (DojoAjaxUpdatingBehavior dojoAjaxUpdatingBehavior :
select.getBehaviors(DojoAjaxUpdatingBehavior.class)) {

          if (isNoOpEvent(dojoAjaxUpdatingBehavior.getEvent())) {

            dojoAjaxUpdatingBehavior.onUpdate(target);

          }

        }

      }

    }

  }

 

All of which works just fine, and I'm happy with it. However, if the
select was the last ajax callback fired, and the page is reloaded, then
wicket adds
"&select.2.value=MY_SELECTION_CHOICE&select.2.initial=false", or
something similar, to the page url, and that then ends up in every
subsequent ajax request, which messes the works up terribly. I've tried
different methods of telling wicket not to add the last request
parameters to no avail. The page should not be reloaded, but if it is,
it's broken, and that bothers me. This behavior seems to be involved
with RequestCycle.get().getUrlRenderer().getBaseUrl(), and the code in
the default behavior...

 

                                Url baseUrl =
RequestCycle.get().getUrlRenderer().getBaseUrl();

                                CharSequence ajaxBaseUrl =
Strings.escapeMarkup(baseUrl.toString());

 
response.renderJavaScript("Wicket.Ajax.baseUrl=\"" + ajaxBaseUrl +
"\";",

                                                "wicket-ajax-base-url");

 

I think it runs deeper than that however, because setting the base url
with...

 

   RequestCycle.get().getUrlRenderer().setBaseUrl(URL.pase(""));

 

...in onBeforeRender() or onAfterRender() hasn't stopped it. Maybe I
have the set in the wrong place? In any case, if anyone knows...

 

1)      Why wicket caches the query parameters and adds them to the base
url?

2)      How to stop wicket from doing?

 

...then I'd appreciate it.

 

Thanks in advance for any help,

 

David

Reply via email to