You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Berkman <da...@glu.com> on 2011/10/25 00:09:03 UTC

Problem with ajax base url

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


RE: Problem with Panel default model

Posted by David Berkman <da...@glu.com>.
It does...

  private static final ThreadLocal<Boolean> STRIP_TAGS_LOCAL = new ThreadLocal<Boolean>();

  @Override
  protected void onBeforeRender () {

    super.onBeforeRender();

    STRIP_TAGS_LOCAL.set(Application.get().getMarkupSettings().getStripWicketTags());
    Application.get().getMarkupSettings().setStripWicketTags(true);
  }

  @Override
  protected void onAfterRender () {

    Application.get().getMarkupSettings().setStripWicketTags(STRIP_TAGS_LOCAL.get());

    super.onAfterRender();
  }

...using these methods to strip wicket tags for the rendering of this panel only. But, both onBeforeRender() and onAfterRender() are calling the same methods on their super class, which is Panel, and I'm not touching any models.

David 


-----Original Message-----
From: Andrea Del Bene [mailto:adelbene@ciseonweb.it] 
Sent: Wednesday, October 26, 2011 1:13 AM
To: users@wicket.apache.org
Subject: Re: Problem with Panel default model

Hi,

does your page override onBeforeRender method? Can you show the code?
> Thank you. Upgrade to 1.5.2 did seem to resolve the issue with the last ajax request parameters being pushed onto the base url. However, testing that resolution exposed a further problem. I'm using a org.apache.wicket.markup.html.panel.Panel into which I'm handing the a org.apache.wicket.model.Model and setting it as the default model via the constructor...
>
>    public class MyPanel extends Panel {
>
>      public MyPanel (final String id, final IModel<>  model) {
>
>        super(id, model);
>      }
>    }
>
>
> The model in question stores a java Enum, call it MyEnum...
>
>    public enum MyEnum {
>
>      ONE, TWO, THREE
>    }
>
>    new MyPanel("panelId", new Model<MyEnum>(MyEnum.values()[0]));
>
>
> On an ajax callback I update the model on this panel...
>
>    public class MyPanel extends Panel {
>
>      ...
>
>      public void setValue (String value) {
>
>        setDefaultModelObject(MyEnum.value(value));
>      }
>    }
>
> ...all of which works fine. The problem is that the value which is set at the time of the first page reload is the value that will be reset upon any subsequent page reload. The model updates correctly on the MyPanel instance responding to each ajax callback. Not a problem. But when I reload the page, the value of the model will revert to whatever value it had after the *first* page reload. I notice that the default model instance changes upon page reload. So, for example...
>
> 1) MyPanel holds Model@1234
> 2) set Model@1234 to value MyEnum.TWO, no problem
> 3) page reload...
> 4) MyPanel now holds Model@2345 which holds MyEnum.TWO... this is correct, but the Model instance has changed.
> 5) set Model@2345 to value MyEnum.THREE, no problem
> 6) page reload...
> 7) MyPanel now holds Model@3456 which holds MyEnum.TWO, where did MyEnum.TWO come from?
> 8) I can now continue to set the model value via ajax callbacks, and all is well, and the Model@3456 holds its values just fine
> 9) page reload...
> 10) No matter what the value of the Model@3456 was last set to, MyPanel now holds new instance Model@4567 which *will* hold MyEnum.TWO
>
> Anyone know what's going on?
>
> Thank you,
> David
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Monday, October 24, 2011 10:24 PM
> To: users@wicket.apache.org
> Subject: Re: Problem with ajax base url
>
> Hi
>
> Try with 1.5.2.
> This is fixed with https://issues.apache.org/jira/browse/WICKET-4109
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Problem with Panel default model

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
Hi,

does your page override onBeforeRender method? Can you show the code?
> Thank you. Upgrade to 1.5.2 did seem to resolve the issue with the last ajax request parameters being pushed onto the base url. However, testing that resolution exposed a further problem. I'm using a org.apache.wicket.markup.html.panel.Panel into which I'm handing the a org.apache.wicket.model.Model and setting it as the default model via the constructor...
>
>    public class MyPanel extends Panel {
>
>      public MyPanel (final String id, final IModel<>  model) {
>
>        super(id, model);
>      }
>    }
>
>
> The model in question stores a java Enum, call it MyEnum...
>
>    public enum MyEnum {
>
>      ONE, TWO, THREE
>    }
>
>    new MyPanel("panelId", new Model<MyEnum>(MyEnum.values()[0]));
>
>
> On an ajax callback I update the model on this panel...
>
>    public class MyPanel extends Panel {
>
>      ...
>
>      public void setValue (String value) {
>
>        setDefaultModelObject(MyEnum.value(value));
>      }
>    }
>
> ...all of which works fine. The problem is that the value which is set at the time of the first page reload is the value that will be reset upon any subsequent page reload. The model updates correctly on the MyPanel instance responding to each ajax callback. Not a problem. But when I reload the page, the value of the model will revert to whatever value it had after the *first* page reload. I notice that the default model instance changes upon page reload. So, for example...
>
> 1) MyPanel holds Model@1234
> 2) set Model@1234 to value MyEnum.TWO, no problem
> 3) page reload...
> 4) MyPanel now holds Model@2345 which holds MyEnum.TWO... this is correct, but the Model instance has changed.
> 5) set Model@2345 to value MyEnum.THREE, no problem
> 6) page reload...
> 7) MyPanel now holds Model@3456 which holds MyEnum.TWO, where did MyEnum.TWO come from?
> 8) I can now continue to set the model value via ajax callbacks, and all is well, and the Model@3456 holds its values just fine
> 9) page reload...
> 10) No matter what the value of the Model@3456 was last set to, MyPanel now holds new instance Model@4567 which *will* hold MyEnum.TWO
>
> Anyone know what's going on?
>
> Thank you,
> David
>
>
> -----Original Message-----
> From: Martin Grigorov [mailto:mgrigorov@apache.org]
> Sent: Monday, October 24, 2011 10:24 PM
> To: users@wicket.apache.org
> Subject: Re: Problem with ajax base url
>
> Hi
>
> Try with 1.5.2.
> This is fixed with https://issues.apache.org/jira/browse/WICKET-4109
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Problem with Panel default model

Posted by kiranduba <ki...@gmail.com>.
Hi David,
Did you found the solution for this problem? I'm also facing such kind of
issue. I have a Model with list of POJO. On drag/drop i'm giving ajax call
and updating the paramter in POJO which is in Model. If I call sort on the
list of POJO based on parameter the Model reset's to the initial stage when
page is rendered. So if i do drag/drop again it picks up the wrong POJO
element in the model. Please suggest I'm stuck at this point. I'm using
Wicket 6 with AbstractAjaxBehaviour.

Thanks,
Kiran Duba



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Problem-with-ajax-base-url-tp3934751p4661243.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Problem with Panel default model

Posted by David Berkman <da...@glu.com>.
Thank you. Upgrade to 1.5.2 did seem to resolve the issue with the last ajax request parameters being pushed onto the base url. However, testing that resolution exposed a further problem. I'm using a org.apache.wicket.markup.html.panel.Panel into which I'm handing the a org.apache.wicket.model.Model and setting it as the default model via the constructor...

  public class MyPanel extends Panel {

    public MyPanel (final String id, final IModel<> model) {

      super(id, model);
    }
  }


The model in question stores a java Enum, call it MyEnum...

  public enum MyEnum {

    ONE, TWO, THREE
  }

  new MyPanel("panelId", new Model<MyEnum>(MyEnum.values()[0]));


On an ajax callback I update the model on this panel...

  public class MyPanel extends Panel {

    ...

    public void setValue (String value) {

      setDefaultModelObject(MyEnum.value(value));
    }
  }

...all of which works fine. The problem is that the value which is set at the time of the first page reload is the value that will be reset upon any subsequent page reload. The model updates correctly on the MyPanel instance responding to each ajax callback. Not a problem. But when I reload the page, the value of the model will revert to whatever value it had after the *first* page reload. I notice that the default model instance changes upon page reload. So, for example...

1) MyPanel holds Model@1234
2) set Model@1234 to value MyEnum.TWO, no problem
3) page reload...
4) MyPanel now holds Model@2345 which holds MyEnum.TWO... this is correct, but the Model instance has changed.
5) set Model@2345 to value MyEnum.THREE, no problem
6) page reload...
7) MyPanel now holds Model@3456 which holds MyEnum.TWO, where did MyEnum.TWO come from?
8) I can now continue to set the model value via ajax callbacks, and all is well, and the Model@3456 holds its values just fine
9) page reload...
10) No matter what the value of the Model@3456 was last set to, MyPanel now holds new instance Model@4567 which *will* hold MyEnum.TWO

Anyone know what's going on?

Thank you,
David


-----Original Message-----
From: Martin Grigorov [mailto:mgrigorov@apache.org] 
Sent: Monday, October 24, 2011 10:24 PM
To: users@wicket.apache.org
Subject: Re: Problem with ajax base url

Hi

Try with 1.5.2.
This is fixed with https://issues.apache.org/jira/browse/WICKET-4109


Re: Problem with ajax base url

Posted by Martin Grigorov <mg...@apache.org>.
Hi

Try with 1.5.2.
This is fixed with https://issues.apache.org/jira/browse/WICKET-4109

On Tue, Oct 25, 2011 at 12:09 AM, David Berkman <da...@glu.com> wrote:
> 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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org