user193116 user193116 - 4 months ago 27x
jQuery Question

Using Wicket AbstractAjaxBehavior with jQuery.ajax()

I have used the jQuery AJax call to send JSON as documented here in StackOverflow

The problem is that I am not receiving any Data on the server . I can see that the call did reach the target ajax behavior -- but in onRequest() method , the RequestCycle dd not contain any parameters

My Wicket Code:

AbstractAjaxBehavior ajaxSaveBehaviour = new AbstractAjaxBehavior(){
private static final long serialVersionUID = 1L;

public void onRequest()
//get parameters
final RequestCycle requestCycle = RequestCycle.get();

final PageParameters pageParameters = new PageParameters(requestCycle.getRequest().getParameterMap());" I have received something 1");

for(String pkey: requestCycle.getRequest().getParameterMap().keySet()){
String[] valArry= requestCycle.getRequest().getParameterMap().get(pkey);
StringBuffer sb = new StringBuffer();
for(String s: valArry) sb.append(s).append(" , ");"pk :"+ pkey + " = "+ sb.toString());

//do something using nice json library to produce a string of json" I have received something 2");
for(String key: pageParameters.keySet()){
Object o= pageParameters.get(key);"received key : "+ key + " = " +o.toString());

String data="ok";

requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data));

String callBackURL= ajaxSaveBehaviour.getCallbackUrl().toString();

My Javascript that invokes this method

console.log(" call back url :"+ callBackURL);
url: callBackURL,
type: 'post',
cache: false,

contentType: 'application/json',
dataType: 'json',
complete: function() {
alert(" completed okey dokey!")


From my Firebug console, I can see that the JSON POST was made succesfully and the alert(" completed okey dokey!") dos get triggered.

The problem is that on the Wicket AbstractAjaxBehavior is unable to find any parameters in the RequestCycle.

Is there something I am missing ? The funny thing is that I ran this is debugger asn I could not find any parameter. This looks like an encoding issue.

From Firebug, I could see that this was the call that was made


Somehow , these parameters do not apperd in the RequestCycle. It looks like an encodong issue . Any ideas ?


ok I found the solution : The keys was to not use requestCycle.getRequest().getParameterMap() to read the JSON from the browser. Instead read the data directly from the servlet input stream as below: It works .

            public void onRequest()
            //get parameters
            final RequestCycle requestCycle = RequestCycle.get();

            WebRequest wr=(WebRequest)requestCycle.getRequest();

            HttpServletRequest hsr= wr.getHttpServletRequest() ;

            try {
                BufferedReader br = hsr.getReader();

                       String  jsonString = br.readLine();
                       if((jsonString==null) || jsonString.isEmpty()){
                           logger.error(" no json found");
                       else {
                 " json  is :"+ jsonString);

            } catch (IOException ex) {

            // json string to retir to the jQuery onSuccess function
            String data=getReturnJSONValue();

  "returning json :"+ data);
            IRequestTarget t = new StringRequestTarget("application/json", "UTF-8", data);

            //requestCycle.setRequestTarget(new StringRequestTarget("application/json", "utf-8", data));