You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Brown, Berlin [GCG-PFS]" <Be...@Primerica.com> on 2011/12/07 02:41:26 UTC

Convert wicket ajax posts do wicket ajax get requests

I am having issues with IE and ajax post requests.
 
The issue is reported here:
http://support.microsoft.com/kb/895954
 
As a way to address the issue, I was thinking of addressing the
application.  There are several places with ajax post requests.  I was
trying to see if I can convert those requests to wicket ajax gets
requests.
 
I am talking about radio buttons and onchange drop down boxes.
 
In this behavior, how would I make a change to use wicketAjaxGet and
keep the general functionality?
 
public abstract class AjaxFormChoiceComponentUpdatingBehavior extends
AbstractDefaultAjaxBehavior:
   
protected final CharSequence getEventHandler()
 {
  return generateCallbackScript(new
AppendingStringBuffer("wicketAjaxPost('").append(
   getCallbackUrl()).append(
   "', wicketSerializeForm(document.getElementById('" +
getComponent().getMarkupId() +
    "',false))"));
 }

Re: Convert wicket ajax posts do wicket ajax get requests

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

On Wed, Dec 7, 2011 at 2:41 AM, Brown, Berlin [GCG-PFS]
<Be...@primerica.com> wrote:
> I am having issues with IE and ajax post requests.
>
> The issue is reported here:
> http://support.microsoft.com/kb/895954
>
> As a way to address the issue, I was thinking of addressing the
> application.  There are several places with ajax post requests.  I was
> trying to see if I can convert those requests to wicket ajax gets
> requests.
>
> I am talking about radio buttons and onchange drop down boxes.
>
> In this behavior, how would I make a change to use wicketAjaxGet and
> keep the general functionality?
>
> public abstract class AjaxFormChoiceComponentUpdatingBehavior extends
> AbstractDefaultAjaxBehavior:
>
> protected final CharSequence getEventHandler()
>  {
>  return generateCallbackScript(new
> AppendingStringBuffer("wicketAjaxPost('").append(
>   getCallbackUrl()).append(
>   "', wicketSerializeForm(document.getElementById('" +
> getComponent().getMarkupId() +
>    "',false))"));
>  }

You need to use wicketAjaxGet instead and you need to concatenate the
result of wicketSerializeForm() to the result of getCallbackUrl().
Something like:

protected final CharSequence getEventHandler()
  {
  return generateCallbackScript(new
 AppendingStringBuffer("wicketAjaxGet('").append(
   getCallbackUrl()).append('&').append("'+wicketSerializeForm(document.getElementById('"
+
 getComponent().getMarkupId() +
    ",false))"));
  }

I didn't test the above!
It should produce something like:
wicketAjaxGet('some/url/to/the/behavior&' +
wicketSerializeForm(document.getElementById('formId')))

In Wicket 6.0 this will look like:
Wicket.ajax({
  u: 'some/url/to/the/behavior',
  f: 'formId',
  e: 'click',
  c: 'componentId'
});

Explanation:
by default Wicket.ajax() will do GET requests, if you need POST then
you need to add additional parameter: m: 'POST'.
'u' is the url for the request
'f' is the optional id of the form which elements should be serialized
and used as parameters
'e' is the name of the event that should trigger the Ajax request
'c' is the id of the component that will trigger the Ajax request when
the event happens

There are also optional parameters for adding additional (custom)
parameters to Ajax request, but all this will be soon documented in
the "Ajax in Wicket 6.0" wiki page. The JSON object used as parameter
for Wicket.ajax() is generated by Wicket Ajax behaviors for you, but
you can also use this API in your own .js files.

I hope the new API is easier to understand and use :-)

-- 
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