Hi MoShAn480,
I tried to use your plugin with Spring 3, but I could not make it to work. The remoting method in my Controller got called, but the result returned is null. Do you know what I did wrong?
package com.xxx.web;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import com.google.code.springextjs.remoting.spring3.controller.ExtJsRemotingController;
import com.google.code.springextjs.remoting.annotations.Annotations.ExtJsRemotingMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import java.text.MessageFormat;
//@Controller
@RequestMapping(value = "/extjs/remoting")
public class MyController extends ExtJsRemotingController {
protected final Log logger = LogFactory.getLog(getClass());
@ExtJsRemotingMethod (paramLength = 2)
public int sum(int a,int b) {
return a+b;
}
@ExtJsRemotingMethod (paramLength = 2)
public String multiply(int a,int b){
return "Result : "+(a*b);
}
@ExtJsRemotingMethod (paramLength = 3)
public String echo(String string,boolean bool, int integer){
return MessageFormat.format("String {0} boolean {1} integer {2}", string, bool, integer);
}
}
var remotingProvider = new Ext.direct.RemotingProvider (REMOTING_API);
Ext.Direct.addProvider(remotingProvider);
var out = new Ext.form.DisplayField({
cls: 'x-form-text',
id: 'out'
});
var text = new Ext.form.TextField({
width: 300,
emptyText: 'Echo input'
});
var call = new Ext.Button({
text: 'Echo',
handler: function(){
MyRemotingApi.echo(text.getValue(),true,26,function(result,e){
var t = e.getTransaction();
out.append(String.format('<p><b>Successful call to {0}.{1} with response:</b><xmp>{2}</xmp></p>',
t.action, t.method, Ext.encode(result)));
out.el.scrollTo('t', 100000, true);
});
// MyRemotingApi.doEcho(text.getValue(), function(result, e){
// var t = e.getTransaction();
// out.append(String.format('<p><b>Successful call to {0}.{1} with response:</b><xmp>{2}</xmp></p>',
// t.action, t.method, Ext.encode(result)));
// out.el.scrollTo('t', 100000, true);
// });
}
});
var num = new Ext.form.TextField({
width: 80,
emptyText: 'Multiply x 8',
style: 'text-align:left;'
});
var multiply = new Ext.Button({
text: 'Multiply',
handler: function(){
MyRemotingApi.multiply(num.getValue(),8, function(result, e){
var t = e.getTransaction();
if(e.status){
out.append(String.format('<p><b>Successful call to {0}.{1} with response:</b><xmp>{2}</xmp></p>',
t.action, t.method, Ext.encode(result)));
}else{
out.append(String.format('<p><b>Call to {0}.{1} failed with message:</b><xmp>{2}</xmp></p>',
t.action, t.method, e.message));
}
out.el.scrollTo('t', 100000, true);
});
}
});
text.on('specialkey', function(t, e){
if(e.getKey() == e.ENTER){
call.handler();
}
});
num.on('specialkey', function(t, e){
if(e.getKey() == e.ENTER){
multiply.handler();
}
});
var p = new Ext.Panel({
title: 'Remote Call Log',
//frame:true,
width: 600,
height: 300,
layout:'fit',
I added an example web app and additional dependency jars in SVN. I did find though while building the sample web app that there is a bug with handling primitive and their wrappers as return types. I will resolve this tomorrow.
Actually I found that the multiply in your example is sending a string but you are expecting int to do the multiplication. Change the ints to Strings and parse int values, otherwise send numeric values in your remote json request. I have updated the example controller in the sample code to reflect this in SVN.
Actually I found that the multiply in your example is sending a string but you are expecting int to do the multiplication. Change the ints to Strings and parse int values, otherwise send numeric values in your remote json request. I have updated the example controller in the sample code to reflect this in SVN.
Let me know if you have more questions.
Hi,
Could you please also post the code of com.google.code.springextjs.sample.RemotingController class also? I still could not make it work and I am not sure it is because of the path passed into ExtJsRemotingUtil.createExtRemotingApiString ? Is it supposed to be "/controller/extjs/remoting/router" ?
I tried all the following options, but they all did not work:
/controller/extjs/remoting/router
/extjs/remoting/router
/extjs/remoting
In the Remote Call Log, I got the following messages:
"Successful call to MyRemotingApi.echo with response: null'
"Call to MyRemotingApi.multiply failed with message: Unable to connect to the server."