1. #1

    Default Using ExtJS in Java with jabsorb or json-rpc-java

    Using ExtJS in Java with jabsorb or json-rpc-java


    UPDATE 2008-04-22: Created new post in the plugins forum here: http://extjs.com/forum/showthread.php?t=33353
    PLEASE POST YOUR COMMENTS/QUESTIONS THERE!

    UPDATE 2008-04-21
    : Full demo and source code is now online here: http://jabsorb.org/jabsorb-trunk/projectmetrics.html

    I've recently starting learning ExtJS. I must say, I'm very impressed. It's quite elegant, powerful and beautiful. The only issue I have is that it's a bit big... I spent a little time trying to make a smaller custom ExtJS build-- but it's still big! (mainly because I wanted to use a lot of the features!) That point aside, it's a great framework that I'll be spending a lot of time with in the upcoming days...

    My first goal was to get the grid working with my favorite server side framework, jabsorb. After some extensive searching, I could not find anyone else using ExtJS with jabsorb or json-rpc-java, so I coded it up!

    jabsorb and json-rpc-java abstract away the whole server side interaction from you so you don't need to worry about URLs, XHR or even data serialization/transformation...

    So, what I did was make a new kind of proxy, I based my code off of the HttpProxy, but it really just wraps a json-rpc call/callback.

    This worked beautifully with the jabsorb framework and an ExtJS JsonReader. If anyone is interested, I will try and post a more complete example and demo with some server side code, later.

    Here's the code:

    Code:
    /**
     * @class Ext.data.JsonRpcProxy
     * @extends Ext.data.DataProxy
     * 
     * An implementation of Ext.data.DataProxy that invokes a json-rpc method call
     * via the json-rpc-java and/or jabsorb library to retrieve the data needed by 
     * the Reader when it's load method is called.
     * 
     * @constructor
     * @param {Function} rpc The jabsorb or json-rpc-java function to call to 
     *                     retrieve the data object which the Reader uses to 
     *                     construct a block of Ext.data.Records.  When invoked,
     *                     it will be passed one json object containing the call 
     *                     parameters used to retrieve and optionally sort the data
     *                     and a second callback function to load the resultant
     *                     data from the result of the rpc call.
     */
    Ext.data.JsonRpcProxy = function(rpc) {
        Ext.data.JsonRpcProxy.superclass.constructor.call(this);
        this.rpc = rpc;
    };
    
    Ext.extend(Ext.data.JsonRpcProxy, Ext.data.DataProxy, {
        /**
         * Load data from the requested source read the data object into
         * a block of Ext.data.Records using the passed Ext.data.DataReader 
         * implementation and process that block using the passed callback.
         * 
         * @param {Object} params This parameter is not used by the JsonRpcProxy class.
         * @param {Ext.data.DataReader) reader The Reader object which converts the data
         * object into a block of Ext.data.Records.
         * @param {Function} callback The function into which to pass the block of Ext.data.records.
         * The function must be passed <ul>
         * <li>The Record block object</li>
         * <li>The "arg" argument from the load function</li>
         * <li>A boolean success indicator</li>
         * </ul>
         * @param {Object} scope The scope in which to call the callback
         * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
         */
        load : function(params, reader, callback, scope, arg){
            if(this.fireEvent("beforeload", this, params) !== false)
            {
              var  o = {
                params : params || {},
                request: {
                    callback : callback,
                    scope : scope,
                    arg : arg
                },
                reader: reader,
                callback : this.loadResponse,
                scope: this
              };
    
              this.rpc(function(r,e){o.callback.call(o.scope,o,r&&!e, r||e);}, o.params);
            }
            else
            {
              callback.call(scope||this, null, arg, false);
            }
        },
    
        // private
        loadResponse : function(o, success, response){
            if(!success){
                this.fireEvent("loadexception", this, o, response);
                o.request.callback.call(o.request.scope, null, o.request.arg, false);
                return;
            }
            var result;
            try {
                result = o.reader.readRecords(response);
            }catch(e){
                this.fireEvent("loadexception", this, o, response, e);
                o.request.callback.call(o.request.scope, null, o.request.arg, false);
                return;
            }
            this.fireEvent("load", this, o, o.request.arg);
            o.request.callback.call(o.request.scope, result, o.request.arg, true);
        },
    
        // private
        update : function(dataSet){
        },
    
        // private
        updateResponse : function(dataSet){
        }
    });
    This will also work perfectly for the older json-rpc-java server side framework which jabsorb is based on, and indeed should work with any back end json-rpc 1.0 compliant server, (using the jsonrpc.js front end call methodology from jabsorb or json-rpc-java.)

    I just wrote this as if it were part of ExtJS and indeed it would be great if it were in a future release if the code is up to the ExtJS team's standards. If there are problems or issues with it, please point that out to me (I'm still quite new to ExtJS) -- I'd like this to be a good clean reusable implementation...
    Last edited by Arthur.Blake; 22 Apr 2008 at 2:27 PM. Reason: update location of demo

  2. #2
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    Welcome to the Ext community
    very neat work indeed.

    as a jabsorb user, could you throw a little light on jabsorb vs dwr?
    (i've been meaning to start on dwr and the DWRProxy (improved) plugin by @loeppky, but now that you've dangled a competing framework in front of me... )

    p.s. you might also want to start a thread (with a link back here) in the 2.0 User Extensions and Plugins forum for your plugin.

  3. #3

    Default


    Thanks for the welcome!

    I answered that very question a couple of months ago here:

    http://tech.groups.yahoo.com/group/json/message/933

  4. #4
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    thanks for the info

    (and after taking a peek at the committers' list, pardon me for mistaking you for a mere jabsorb user )

  5. #5

    Default


    No offense taken whatsoever. After all, I am a very active user (and I just happen to be a committer as well )

  6. #6
    Ext User
    Join Date
    Mar 2008
    Posts
    3
    Vote Rating
    0
    jbeasley is on a distinguished road

      0  

    Default


    Thank you for your post on the JsonRpcProxy using ExtJS. I'm just learning ExtJS as well, and am also impressed by the framework and it's features.

    I was looking to create a service without the XML overhead, and would be interested in seeing what's all involved in a working example of jabsorb w/ExtJS when ones available.

  7. #7
    Ext User
    Join Date
    Apr 2008
    Posts
    8
    Vote Rating
    0
    Czy is on a distinguished road

      0  

    Default


    Hi, Arthur.

    Quote Originally Posted by Arthur.Blake View Post
    This worked beautifully with the jabsorb framework and an ExtJS JsonReader. If anyone is interested, I will try and post a more complete example and demo with some server side code, later.
    I have very, very interested in this example and demo. Jabsorb and Ext can be very nice conjuntion.
    Thank you very much, Arthur.

  8. #8

    Default


    I will try and get a more complete example together very soon.

  9. #9
    Ext User
    Join Date
    Apr 2008
    Posts
    8
    Vote Rating
    0
    Czy is on a distinguished road

      0  

    Default


    Hi, Arthur

    Have you try some complete example already?

    I need to know how use the jabsorb framework with an ExtJS JsonReader. It's very important for me.

    Thanks you very much, Arthur.

  10. #10
    Ext User
    Join Date
    Jul 2007
    Location
    Jakarta
    Posts
    75
    Vote Rating
    0
    flatburger is on a distinguished road

      0  

    Default


    can we have a full bundle example that we can test it here

    we develop a backend system using jabsorb also, json -rpc

    take a look at

    httP//source.meruvian.com

    they idea of our project, we develop proto to consume json server and read by swing, javame and extjs.

    glad if we can exchange this experience.
    Frans Thamura
    Meruvian Foundation
    Jakarta
    indonesia

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi