1. #41
    Ext User
    Join Date
    Apr 2007
    Posts
    131
    Vote Rating
    0
    MoShAn480 is on a distinguished road

      0  

    Default


    Works with Java 1.6 as well.

  2. #42
    Ext User
    Join Date
    Jan 2010
    Posts
    33
    Vote Rating
    0
    tungchau is on a distinguished road

      0  

    Default


    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);
    }
    }

    ===============direct.js=================================
    /*
    * Ext JS Library 3.0 RC1
    * Copyright(c) 2006-2009, Ext JS, LLC.
    * licensing@extjs.com
    *
    * http://extjs.com/license
    */
    Ext.onReady(function(){

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

    items: [out],
    bbar: [text, call, '-', num, multiply]
    }).render(Ext.getBody());
    Ext.Direct.on('message', function(e){
    out.append(String.format('<p><i>{0}</i></p>', e.data));
    out.el.scrollTo('t', 100000, true);
    });
    });
    ==============index.jsp===========================
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Customer Portal</title>
    <link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="../ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="../ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    <%= com.google.code.springextjs.remoting.util.ExtJsRemotingUtil.createExtRemotingApiString(
    request.getContextPath() + "/extjs/remoting/router",
    com.xxx.web.MyController.class,
    "MyRemotingApi")%>
    </script>
    <script language="javascript" src="../javascripts/direct.js"></script>
    </head>
    <body style="margin:10px;">
    </body>
    </html>

  3. #43
    Ext User
    Join Date
    Apr 2007
    Posts
    131
    Vote Rating
    0
    MoShAn480 is on a distinguished road

      0  

    Default


    Hi,

    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.

  4. #44
    Ext User
    Join Date
    Apr 2007
    Posts
    131
    Vote Rating
    0
    MoShAn480 is on a distinguished road

      0  

    Default


    Hi,

    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.

  5. #45
    Ext User
    Join Date
    Jan 2010
    Posts
    33
    Vote Rating
    0
    tungchau is on a distinguished road

      0  

    Default


    Quote Originally Posted by MoShAn480 View Post
    Hi,

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

    Thanks,
    Tung Chau

  6. #46
    Ext User
    Join Date
    Jan 2010
    Posts
    33
    Vote Rating
    0
    tungchau is on a distinguished road

      0  

    Default


    I wonder whether I did the annotation correctly...

    ==============RemotingController.java=======
    package com.sample.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;
    @RequestMapping(value = "/controller/extjs/remoting")
    public class RemotingController extends ExtJsRemotingController {
    protected final Log logger = LogFactory.getLog(getClass());
    @ExtJsRemotingMethod (paramLength = 1)
    public String multiply(int a){
    return "Result : "+(a*8);
    }
    @ExtJsRemotingMethod (paramLength = 1)
    public String doEcho(String string){
    return MessageFormat.format("String {0}", string);
    }
    }
    ============================================
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>ExtJS Direct and Spring</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    <%= com.google.code.springextjs.remoting.util.ExtJsRemotingUtil.createExtRemotingApiString(
    request.getContextPath() + "/controller/extjs/remoting/router",
    com.sample.web.RemotingController.class,
    "TestAction")%>
    </script>
    <script language="javascript" src="${pageContext.request.contextPath}/javascripts/direct.js"></script>
    </head>
    <body style="margin:10px;">
    </body>
    </html>
    ===============direct.js==================
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>ExtJS Direct and Spring</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    <%= com.google.code.springextjs.remoting.util.ExtJsRemotingUtil.createExtRemotingApiString(
    request.getContextPath() + "/controller/extjs/remoting/router",
    com.sample.web.RemotingController.class,
    "TestAction")%>
    </script>
    <script language="javascript" src="${pageContext.request.contextPath}/javascripts/direct.js"></script>
    </head>
    <body style="margin:10px;">
    </body>
    </html>
    ==============springapp-servlet.xml==============
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>ExtJS Direct and Spring</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    <%= com.google.code.springextjs.remoting.util.ExtJsRemotingUtil.createExtRemotingApiString(
    request.getContextPath() + "/controller/extjs/remoting/router",
    com.sample.web.RemotingController.class,
    "TestAction")%>
    </script>
    <script language="javascript" src="${pageContext.request.contextPath}/javascripts/direct.js"></script>
    </head>
    <body style="margin:10px;">
    </body>
    </html>
    ===================web.xml===============
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>ExtJS Direct and Spring</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/ext/resources/css/ext-all.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/ext/ext-all-debug.js"></script>
    <script type="text/javascript">
    <%= com.google.code.springextjs.remoting.util.ExtJsRemotingUtil.createExtRemotingApiString(
    request.getContextPath() + "/controller/extjs/remoting/router",
    com.sample.web.RemotingController.class,
    "TestAction")%>
    </script>
    <script language="javascript" src="${pageContext.request.contextPath}/javascripts/direct.js"></script>
    </head>
    <body style="margin:10px;">
    </body>
    </html>
    =============The generated index.jsp in the browser looks correct!===========
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Customer Portal</title> <link rel="stylesheet" type="text/css" href="/ext/resources/css/ext-all.css" /> <script type="text/javascript" src="/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="/ext/ext-all-debug.js"></script> <script type="text/javascript"> REMOTING_API = {"actions":{"TestAction":[{"formHandler":false,"len":1,"name":"multiply"},{"formHandler":false,"len":1,"name":"doEcho"}]},"type":"remoting","url":"/controller/extjs/remoting/router"} </script> <script language="javascript" src="/javascripts/direct.js"></script></head><body style="margin:10px;"></body></html>=================================================
    In the Remote Call Log, I got the following messages:

    Successful call to TestAction.doEcho with response:null

    Call to TestAction.multiply failed with message:Unable to connect to the server.


    Please help...

  7. #47
    Ext User
    Join Date
    Jan 2010
    Posts
    33
    Vote Rating
    0
    tungchau is on a distinguished road

      0  

    Default


    Never mind. I found the source code of your sample using svn. Thanks.

  8. #48
    Ext User
    Join Date
    Apr 2007
    Posts
    131
    Vote Rating
    0
    MoShAn480 is on a distinguished road

      0  

    Default


    Hi,

    the example should explain things more. If you still have issues let me know. There is also a pre built sample war on the project's google code site.

  9. #49
    Ext User
    Join Date
    Jan 2010
    Posts
    33
    Vote Rating
    0
    tungchau is on a distinguished road

      0  

    Default


    Thanks. I imported wrong Controller class inside my RemotingController class. That explains why ...

  10. #50
    Ext User
    Join Date
    Apr 2007
    Posts
    131
    Vote Rating
    0
    MoShAn480 is on a distinguished road

      0  

    Default


    Hi,

    just put a 0.9.2-beat release up on Google Code.

    check out at http://code.google.com/p/springextjs...estSpringextjs

    Thanks!