[CLOSED] [1.0] Clean Resource Url makes a lot of difference to Direct calls javascript

  1. #1

    [CLOSED] [1.0] Clean Resource Url makes a lot of difference to Direct calls javascript

    CleanResourceUrl option in web.config makes a lot of difference to generated code for Direct calls (and I am sure, at other places too, I recall my colleague mentioning earlier, that he gets a "Ext is undefined" error with CleanResourceUrl enabled, but I never had a chance to look at it).

    Please see the code below:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    	protected void Page_Load (object sender, EventArgs e)
    	{
    		if (!Ext.Net.X.IsAjaxRequest)
    		{
    			List<object>l=new List<object>();
    			l.Add(new { id = 1, name = "Person1" });
    			l.Add(new { id = 2, name = "Person2" });
    			l.Add(new { id = 3, name = "Person3" });
    			l.Add(new { id = 4, name = "Person4" });
    
    			this.store.DataSource = l;
    			this.store.DataBind();
    		}
    	}
    
    	[Ext.Net.DirectMethod]
    	public void directMethod ()
    	{
    		Ext.Net.Panel p=new Ext.Net.Panel();
    
    		Ext.Net.MultiSelect ms=new MultiSelect();
    		ms.ID="m2";
    		ms.StoreID = "store";
    		ms.DisplayField = "name";
    		ms.ValueField = "id";
    		ms.Width = new Unit(200, UnitType.Pixel);
    		ms.Height = new Unit(200, UnitType.Pixel);
    
    		p.ContentControls.Add(ms);
    
    		Ext.Net.Button b=new Ext.Net.Button();
    		b.Text = "Click me too!";
    		b.OnClientClick = "#{m2}.myCustomMethod();";
    		p.ContentControls.Add(b);
    
    		p.Render(this.Form);
    	}
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
        <script type="text/javascript">
        	Ext.ux.Multiselect.prototype.myCustomMethod = function() {
        		alert('Test');
        	}
        </script>
        <div>
    		<ext:ResourceManager runat="server" />
    		
    		<ext:Store runat="server" ID="store">
    			<Reader>
    				<ext:JsonReader>
    					<Fields>
    						<ext:RecordField Name="id" />
    						<ext:RecordField Name="name" />
    					</Fields>
    				</ext:JsonReader>
    			</Reader>
    		</ext:Store>
    		
    		<ext:MultiSelect runat="server" ID="m1" Width="200" Height="300" StoreID="store" DisplayField="name" ValueField="id" />
    		<ext:Button runat="server" Text="Click Me" OnClientClick="#{m1}.myCustomMethod();" /></ext:Button>
    		<ext:Button runat="server" Text="Make Direct call" OnClientClick="Ext.net.DirectMethods.directMethod();" /></ext:Button>
        </div>
        </form>
    </body>
    </html>
    Try running it with CleanReosureUrl enabled, invoke the DirectMethod, and click the new button "Click me too".
    Everything goes fine, and you get an alert message.

    Now disable cleanresourceurl in web.config, refresh the page, invoke the DirectMethod, and again click the new button "Click me too". This time you get a javascript error.

    On analysis, I found the following to be an issue with clean urls disabled:
    1) You have a control on page that requires non-standard resources (apart from the core ExtJs and Ext.Net resources), like Multiselect.
    2) There's an instance of Multiselect on the page in the initial GET request.
    3) Its resources are loaded onto page.
    4) You override (Ext.override) or add methods to this control's prototype (e.g. a custom method is added to Ext.ux.Multiselect above).
    5) You make a Direct call. More controls are rendered including the one which requires non-standard resources.
    6) With CleanUrls enabled, the toolkit detects that the control resources are already on the page and does not register them again.
    7) However, with clean urls disabled, the toolkit fails to detect the same, and again registers the resource on the page
    Ext.net.ResourceMgr.load([{url:\"/travcom/WebResource.axd?d=V0eKQdBaIZT2bgNG12vsoa1il5G7nZbZ c_HJ3HqIXtWlHTFEUvLLop_JMMdknF0IaoPdWCdvvDpKIP1eKY YYzg2&amp;t=634143215072483426\"})

    This leads to overwriting of the previous prototype of the control, and any custom methods you added/modified to the prototype are lost.

    The existing controls rendered in GET request continue to work fine with the custom methods, but controls rendered in Direct call do not have the custom methods for them, as they have not been added to their prototype.

    This is almost a show-stopper, and I am working for alternatives, but if Ext.Net team can provide a solution quickly, that would be too great (I cannot enable Clean urls because we are in production for a very large deployment, and more issues have been reported with clean urls enabled).[/LIST]
  2. #2
    Hi,

    I found the problem (just ampersand symbol in url is replaced by '&apmp;' in the direct request). The fix should be commited soon. I will notify you
  3. #3
    Hi,

    The fix has been commited. Please update from SVN (http://svn.ext.net/premium/trunk)

    If you don't want to update your version then please replace 'contains' method in the 'svn.ext.net\trunk\Ext.Net\Build\Ext.Net\extnet\co re\net\ResourceMgr.js' file by the following code

    contains : function (url) {
                        // workaround, need more universal fix
                        url = url.replace("&amp;", "&");
                        for (var i = 0; i < this.buffer.length; i++) {                        
                            if (this.buffer[i].url.replace("&amp;", "&") === url) {
                                return true;
                            }
                        }
                        
                        return false;
                    }
    Last edited by geoffrey.mcgill; Nov 08, 2010 at 6:58 PM.
  4. #4
    Hi vlad, thanks a lot. I think that fix worked.

    And I believe you already knew updating was not an option for us, so thanks for the details also.
    I found it much more easier to do this in one of our js files than to update and re-build core Ext.net code:

    Ext.net.ResourceMgr.queue.contains = function(url) {
        // workaround, need more universal fix
        url = url.replace("&amp;", "&");
        for (var i = 0; i < this.buffer.length; i++) {
            if (this.buffer[i].url.replace("&amp;", "&") === url) {
                return true;
            }
        }
    
        return false;
    }
    You see how you can exploit javascript for something its not intended for :)

Similar Threads

  1. Replies: 1
    Last Post: Sep 20, 2011, 6:02 AM
  2. [CLOSED] Clean GridPanel
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 18, 2011, 9:10 PM
  3. [CLOSED] Direct Method From Javascript
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 17, 2010, 11:17 AM
  4. [CLOSED] Register javascript resource to inherited control
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 11, 2010, 8:24 PM
  5. Replies: 5
    Last Post: Oct 26, 2010, 2:20 PM

Posting Permissions