1. #1
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default another asp.net/jayrock with Ext integration

    another asp.net/jayrock with Ext integration


    I've created another approach to work more generically with every Ajax.request. (based on the AjaxPro adapter code)

    see http://extjs.com/forum/showthread.php?t=8112 for the original thread.

    Code:

    Code:
    var ext_channel = function(call)
    {
        if (typeof(call.callback) !== 'function')
            throw new Error("The EXT channel does not support synchronous methods.");        
        call.yuiconn = Ext.Ajax.request (
            {
                url: call.url , 
                params: {"JSON-RPC": Ext.encode(call.request)} , 
                success: function(response, options) {
    				call.callback(response.responseText);
    			},                            
                failure: function(response, options) {
    				// not sure what to do here...should be routed to global error handler if available
                    call.callback(response.responseText); 
                }   
            }
        );
        return call ; 
    };
    
    Ext.data.Connection.prototype.handleResponse =
    Ext.data.Connection.prototype.handleResponse.createInterceptor(function(response) {
    	var respht = Ext.util.Format.trim(response.getResponseHeader["Content-Type"]) ;
    	if (respht == "application/json; charset=utf-8") {
            var r = Ext.decode(response.responseText);
            if (r.result !== undefined) {
                response.responseText = r.result;
            } else if (r.error) {
            		response.responseText = r.error;
                this.handleFailure(response);
                return false;
            }
        }
    });
    and a sample to use the JayRock demo sample:

    First include the JsonRpcHandler in your head section like this
    Code:

    Code:
    <script type="text/javascript" src="demo.ashx?proxy&v=2"></script>
    and to call your function like this:
    Code:

    Code:
    DemoService.rpc.echo("yes i did it!", function(r){
     alert(r);
    }).call(ext_channel);
    Now it's even possible to do (if the server side returns a (html) string):
    Code:

    Code:
    Ext.get('element').load('handler.ashx/list?param1=2&param2=1');
    Tips/modifications are welcome!!

    Thanks
    Marco
    Last edited by mdissel; 18 Jul 2007 at 6:47 AM. Reason: IE Fix

  2. #2
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    I've updated the first post to fix a problem with the Content-Type header check in IE.

    (thanks to FritFrut)

    Marco

  3. #3
    Ext User
    Join Date
    Jul 2007
    Posts
    8
    Vote Rating
    0
    dot99 is on a distinguished road

      0  

    Default


    Please, give example of usage with grid.

  4. #4
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    the declaration of the store of your grid is something like this:

    Code:
    new Ext.data.JsonStore({  
        	    url: 'test.ashx/Search',
    	    id: 'someKeyField',
    	    fields: ['Field1',..., 'FieldX']
    		})
    and then call
    grid.load({param:...});

    Thanks

    Marco

  5. #5
    Ext User
    Join Date
    Jul 2007
    Posts
    8
    Vote Rating
    0
    dot99 is on a distinguished road

      0  

    Default


    It fails when I try to call with
    ds.load({params:{start:0, limit:5, sort:"id", dir:"asc"}});

    But when I try to call without params it's ok: ds.load();

    The problem is not in server side since it does not sort or page data yet.
    During debugging I was never inside
    var ext_channel = function(call) {...}

    The error:

    [ArgumentNullException]: Value cannot be null.
    Parameter name: s
    at System.IO.StringReader..ctor(String s)
    at Jayrock.JsonRpc.Web.JsonRpcExecutive.GetRequestReader()
    at Jayrock.JsonRpc.Web.JsonRpcExecutive.ProcessRequest()
    at Jayrock.JsonRpc.Web.JsonRpcServiceFeature.ProcessRequest(HttpContext context)
    at Jayrock.JsonRpc.Web.JsonRpcHandler.ProcessRequest()
    at Jayrock.JsonRpc.Web.JsonRpcHandler.ProcessRequest(HttpContext context)
    at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)



    The Request Headers:
    .....
    Connection keep-alive
    X-Requested-With XMLHttpRequest
    Content-Type application/x-www-form-urlencoded
    Referer https://localhost/............
    Content-Length 36
    Cookie ......
    Pragma no-cache
    Cache-Control no-cache

  6. #6
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    608
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    the ext_channel is never called, because you're not using a json method. My first sample was based on changes i made to the jayrock implementation (see my patch at the berlios project site).

    If you want to use the servers side methods to load data in a grid:
    Code:
    Test.search( .....params ....., function(r){
    			grid.getStore().loadData(r.responseText);
    		}).call(ext_channel);
    where search is methd defined at the server side..

    Thanks

    Marco

  7. #7
    Ext User
    Join Date
    Jul 2007
    Posts
    2
    Vote Rating
    0
    taert is on a distinguished road

      0  

    Default


    Hello Marco,

    I've been trying to get this to work for quite some time now, but it just keeps throwing me this error when I want to load data into a grid:
    Code:
    [Exception... "'Error: The EXT channel does not support synchronous methods.' when calling method: [nsIDOMEventListener::handleEvent]"  nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)"  location: "<unknown>"  data: no]
    A clear (full) example of how to use this with a grid would be greatly appreciated!

    Thanks very much

    Tom

  8. #8
    Ext User
    Join Date
    Mar 2007
    Posts
    80
    Vote Rating
    0
    FritFrut is on a distinguished road

      0  

    Default


    Quote Originally Posted by taert View Post
    A clear (full) example of how to use this with a grid would be greatly appreciated!
    Hello
    There's a more or less full example in the original thread:
    http://extjs.com/forum/showthread.php?t=8112
    and in the tutorial:
    http://extjs.com/learn/Tutorial:Jayrock_with_Ext
    It's a bit different from Marco's version, but works with grid.

    There's only one place to check for callback, at the beginning of the ext_channel, so you should make a breakpoint there and check if there's callback property, and what's its type (perhaps it's a 'string' instead of 'function' ?).

  9. #9
    Ext User
    Join Date
    Jul 2007
    Posts
    2
    Vote Rating
    0
    taert is on a distinguished road

      0  

    Default


    Hello FritFrut,

    First of all, thanks a lot for your response. I already found this tutorial, but that one also wasn't working for me. Undoubtedly it's me being too stupid to fill in the missing pieces myself. The Jayrock part is working just fine. Also, if I set up a simple grid, using a simple Data Store and nothing special, everything works fine. Only paging doesn't work. But if I try to implement the tutorial or Marco's way, nothing works...

    If someone could just post a working example, it would really make my day!

    Tom

  10. #10
    Ext User
    Join Date
    Mar 2007
    Posts
    80
    Vote Rating
    0
    FritFrut is on a distinguished road

      0  

    Default


    Quote Originally Posted by taert View Post
    But if I try to implement the tutorial or Marco's way, nothing works...
    Hmm... I really can't say. Perhaps you are mixing the code from the tutorial and Marco? I don't think they'll mix very well . Also, I'm not sure, but I think that Marco's solution can't handle paging, at least not with the default paging toolbar, because PagingToolbar directly calls load on datastore, so you don't go through the ext_channel, as Marco already explained. My code (tutorial) does paging well, because you can create Store using the JsonRpcProxy, but it's a bit complicated and I don't like to have a new Proxy class just to make paging work... (however, it makes halfway decent tutorial
    So, if you want to make Marco's code work, you should just take his interceptor and channel and do something like this (using the names from the tutorial)

    Code:
    function _createDataStore() 
    {
        var recDef = createRecord() ;
        var ds = new Ext.data.JsonStore({  
    //        url: "handlers/myobjecthandler.ashx", 
    // it seems that the url is not needed, your Jayrock proxy takes care of it
    // !!Note that root and totalProperty are different from tutorial
            root: "data", totalProperty: "total",  
            id: "Id",
    	fields: recDef 
        }) ;
        return ds ;
    }
    
    myObject.rpc.list(0 /*start*/, 5/*limit*/, "" /*sort*/, "" /*dir*/,
     function(r)
     {
       theDataStore.loadData(r.responseText)
     } ).call(Tom.JsonRpcProxy.ext_channel1)
    But, as I said, you can't use paging with this... so it's about the choice, should you write custom pager, or use the code from the tutorial and find what's not working.
    HTH, Tom

Thread Participants: 3

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