See discussion: http://extjs.com/forum/showthread.php?t=67956
Simple example
for more information, please visit our forum thread on the extjs website.
Server side
Create a new servlet on your project :
import ch.swissdotnet.extdirect4j.*;
public class MyExtDirectRouter extends ExtDirectRouter {
@ExtRemoteAction(name = "Action", lazyInit = true)
static public class TestAction {
@ExtRemoteMethod
public Result multy(long a) {
return new Result(a * 2, "just a result");
}
}
@Override
protected void configureActions() {
this.addAction(new AnnotatedAction(TestAction.class));
}
}
Javascript side
Add these line to your index.html :
<script src="MyExtDirectRouter" type="text/javascript">
This will call the Ext.Direct router and set the var Ext.app.REMOTING_API with the followin json object :
Ext.app.REMOTING_API = {"url":"http://localhost:8080/ExtDirectDemo/MyExtDirectRouter","type":"remoting","actions":{"Action":[{"name":"multy","len":1}]}};
Now the provider can be added to Ext.Direct, and the remote methods can be used :
``` Ext.Direct.addProvider(Ext.app.REMOTING_API);
Action.multy(num.getValue(), function(result, e){
var t = e.getTransaction();
if(e.status){
alert("answer is " +result.result + ', message : '+result.msg);
}
});
```