Results 1 to 8 of 8

Thread: How to dynamically pass field value for RESTful URL?

  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    San Diego, CA
    Posts
    158

    Default How to dynamically pass field value for RESTful URL?

    Hello,

    I've used JsonStore plenty of times by passing in params to seed return results but how do you do this for a RESTful URL where part of the URL is the value for a query. For instance, in the following code, how can I pass the value that someone is typing in the combo box for the JsonStore that is used as a store for the combobox. Seems like chicken-and-egg problem. This code results in nothing being rendered because the url for the ScriptTagProxy is undefined because at startup it is not known yet.

    Code:
    Ext.onReady(function() {
    	var remoteJsonStore = new Ext.data.JsonStore({
    		root: 'user',
    		fields: [
    		         {name: 'uid'},
    		         {name: 'name'},
    		         {name: 'email'},
    		         {name: 'dept'}	         
    			],
    		restful: true,
    		proxy: new Ext.data.ScriptTagProxy( {
    			url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + combo.valueField
    		})	
    	});
    	var combo = {
    			xtype: 'combo',
    			fieldLabel : 'Search:',
    			forceSelection : true, 
    			displayField : 'name', 
    			valueField : 'uid', 
    			hiddenName : 'h_uid',
    			loadingText : 'Searching....',
    			minChars : 3, 
    			triggerAction : 'name', 
    			store : remoteJsonStore
    	};
    	
    	new Ext.Window({
    		title      : 'People Searcher',
    		height     : 100,
    		layout     : 'form',
    		labelWidth : 100,
    		bodyStyle  : 'padding: 5px',
    		items      : combo
    	}).show();
    });
    Any advice on how I can code this to wait for the results that are typed in to seed the RESTful URL?

    TIA!

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    1. You can't have restful actions with a ScriptTagProxy. A ScriptTagProxy can only do GET requests.
    2. You will need to write a beforeload event that modifies the url, e.g.
    Code:
    listeners: {
        beforeload: function(store, options){
            var name = options.params.name;
            delete options.params.name;
            store.proxy.setApi('read', {
                url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + name
            });
        }
    }
    3. triggerAction:'name' is invalid. You want:
    Code:
    triggerAction: 'query',
    queryParam: 'name'

  3. #3
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    San Diego, CA
    Posts
    158

    Default

    Thanks Condor! Am I to understand that I should end of with the following:

    Code:
    Ext.onReady(function() {
    	var remoteJsonStore = new Ext.data.JsonStore({
    		root: 'user',
    		fields: [
    		         {name: 'uid'},
    		         {name: 'name'},
    		         {name: 'email'},
    		         {name: 'dept'}	         
    			],
    		proxy: new Ext.data.ScriptTagProxy(),
    		listeners: {
    		    beforeload: function(store, options){
    	        var name = options.params.name;
    	        delete options.params.name;
    	        store.proxy.setApi('read', {
    	            url: 'http://myldapserver/ldap-services/services/ldap/jsonp-getusers/' + name
    	        });
    	    	}
    		}
    	});
    	var combo = {
    			xtype: 'combo',
    			fieldLabel : 'Search:',
    			forceSelection : true, 
    			displayField : 'name', 
    			valueField : 'uid', 
    			hiddenName : 'h_uid',
    			loadingText : 'Searching....',
    			minChars : 3, 
    			typeAhead: 'true',
    			triggerAction: 'query',
    			queryParam: 'name',
    			store: remoteJsonStore
    	};
    	
    	new Ext.Window({
    		title      : 'People Searcher',
    		height     : 100,
    		layout     : 'form',
    		labelWidth : 100,
    		bodyStyle  : 'padding: 5px',
    		items      : combo
    	}).show();
    });
    The problem I'm having now is that options.params.name is null. How is it that I connect the the combobox entered data to the store?

    Thanks.

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    This should work. I don't see any errors.

    Maybe I'm missing something. Try some debugging. What does options.params contain when you enter 3 characters in the combobox?

  5. #5
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    San Diego, CA
    Posts
    158

    Default

    Hmmm...when I set a breakpoint inside the listener, options.params = Object {}. Using Firebug I see no value inside the array.

  6. #6
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    San Diego, CA
    Posts
    158

    Default

    Ok, with some more testing, I see that options.params.name is actually set but only after I step through the beforeload listener, which seems to point to some sort of race condition or sequencing issue. I've tried to play with delays a bit to see if that would help but it consistently sets name after the beforeload. Am I missing something?

  7. #7
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    San Diego, CA
    Posts
    158

    Default

    Well for what's it worth, setting name = this.baseParams.name retrieved the value and allowed me to set the RESTful URL.

  8. #8

    Default

    @locutusUT How are you parsing the http query of LDAP on the server ? Are you parsing it into VBScript or breaking the string ? Can you give some code example ?

Similar Threads

  1. [solved] undefined field mapping on RESTful JsonStore save
    By GDW in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 13 Dec 2009, 9:26 PM
  2. DataProxy restful URL and ADO.NET direct access
    By cumpa in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 27 Jul 2009, 3:29 AM
  3. Get value of combobox and pass to a HTML field
    By sanjshah in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 13 Nov 2008, 10:03 AM
  4. pass params in url
    By ludhiana in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 15 May 2008, 7:17 AM
  5. update HTTPProxy url for RESTFul application
    By pgiraud in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 11 Feb 2008, 6:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •