dandelion / dandelion-datatables

Dandelion component for DataTables
http://dandelion.github.io/components/datatables/
Other
110 stars 49 forks source link

Generated datatables params leak from one page's table to another in production mode #279

Closed harbulot closed 9 years ago

harbulot commented 9 years ago

This is using Dandelion and Dandelion Datatables 0.10.1, with Thymeleaf 2.1.4. I'm able to reproduce the problem in a relatively simple application made of two pages.

Page 1 contains a table with these properties:

    <table id="dummydata1_table" dt:table="true"
        dt:url="@{/dummydata1}" dt:pageable="false"
        dt:filterable="false" dt:sortable="false"
        dt:serverdata="myAjaxTest"
        dt:serverside="true">
        <thead>
            <tr>
                <th dt:property="col_a">Column A</th>
                <th dt:property="col_b">Column B</th>
                <th dt:property="col_c">Column C</th>
            </tr>
        </thead>
    </table>

(There is also a function defined as function myAjaxTest(sSource, aoData, fnCallback, oSettings) { ... }.)

Page 2 contains a table with these properties:

    <table id="dummydata2_table" dt:table="true"
        dt:url="@{/dummydata2}">
        <thead>
            <tr>
                <th dt:property="col_a">Column A</th>
                <th dt:property="col_b">Column B</th>
            </tr>
        </thead>
    </table>

If Page 1 is loaded first once the application is started, going onto Page 2 afterwards leads to this error in the browser: Uncaught ReferenceError: myAjaxTest is not defined.

Looking at the generated script, we indeed get parameters of dummydata1_table included in the definition of dummydata2_table ("fnServerData":myAjaxTest does not belong to table 2):

var oTable_dummydata2table_params={"bPaginate":false,"bServerSide":true,"fnServerData":myAjaxTest,"sAjaxSource":"\/dummydata2","fnInitComplete":function(oSettings,json){oTable_dummydata2table.fnAdjustColumnSizing(true);}

This problem does not happen when Page 2 is the first to be loaded. It also only happens in production mode.

tduchateau commented 9 years ago

Thanks for the detailed explanation. Let's try to reproduce this first with the current SNAPSHOT!

tduchateau commented 9 years ago

Could you please post the generated <script src="..."></script> tags in both Page 1 and 2?

harbulot commented 9 years ago

I've published a full example in https://github.com/harbulot/dandelion-datatables-issue-279

It's a standalone application using Jetty. The main class to run is com.github.harbulot.dandelion_datatables_issue_279.DandelionTestApplication. (I would also suggest using -Didle_timeout=1000, as I'm looking at another potential problem at the same time.) Once started, it should be listening on http://localhost:9012/ .

<script src="/dandelion-assets/b00b59510167e59eef4d0d8e7b5b07f9c507b811/jquery-1.11.0.min.js"></script>
<script src="/dandelion-assets/b00b59510167e59eef4d0d8e7b5b07f9c507b811/datatables-1.9.4.min.js"></script>
<script src="/dandelion-assets/b00b59510167e59eef4d0d8e7b5b07f9c507b811/dandelion-datatables-0.10.0.min.js"></script>

Here is the full /dandelion-assets/b00b59510167e59eef4d0d8e7b5b07f9c507b811/dandelion-datatables-0.10.0.min.js script:

var oTable_dummydata1table=$('#dummydata1_table');var oTable_dummydata1table_params={"bPaginate":false,"bServerSide":true,"fnServerData":myAjaxTest,"sAjaxSource":"\/dummydata1","fnInitComplete":function(oSettings,json){oTable_dummydata1table.fnAdjustColumnSizing(true);},"bFilter":false,"aoColumns":[{"mData":"col_a","sDefaultContent":""},{"mData":"col_b","sDefaultContent":""},{"mData":"col_c","sDefaultContent":""}],"bSort":false}
$(document).ready(function(){oTable_dummydata1table.dataTable(oTable_dummydata1table_params);});
<script src="/dandelion-assets/92418c03b292fe6167bbf09e1cbd015a07fa0d04/jquery-1.11.0.min.js"></script>
<script src="/dandelion-assets/92418c03b292fe6167bbf09e1cbd015a07fa0d04/datatables-1.9.4.min.js"></script>
<script src="/dandelion-assets/92418c03b292fe6167bbf09e1cbd015a07fa0d04/dandelion-datatables-0.10.0.min.js"></script>

Here is the full /dandelion-assets/92418c03b292fe6167bbf09e1cbd015a07fa0d04/dandelion-datatables-0.10.0.min.js script:

var oTable_dummydata2table=$('#dummydata2_table');var oTable_dummydata2table_params={"bPaginate":false,"bServerSide":true,"fnServerData":myAjaxTest,"sAjaxSource":"\/dummydata2","fnInitComplete":function(oSettings,json){oTable_dummydata2table.fnAdjustColumnSizing(true);},"bFilter":false,"aoColumns":[{"mData":"col_a","sDefaultContent":""},{"mData":"col_b","sDefaultContent":""}],"bSort":false}
$(document).ready(function(){oTable_dummydata2table.dataTable(oTable_dummydata2table_params);});

("fnServerData":myAjaxTest shouldn't be there.)


I've tried with the latest wip/0.11.0 branches for dandelion and dandelion-datatables using 0.11.0-SNAPSHOT, but it doesn't find various resources like /dandelion/jquery/js/jquery.js. (I don't have any servlet configured for /dandelion/, only for /dandelion-assets/.) Presumably, something changed in the way bundles are included in version 0.11.0-SNAPSHOT. Sorry I haven't following the development in details, so I'm not sure how to fix this little problem and test the rest.

tduchateau commented 9 years ago

A caching issue was present in 0.10.x. Now fixed in the next version. Sorry but I cannot find the relevant commit :-/