Hi Lidija, I had a similar question myself about conditionally including libraries and I believe you can find the answer here: http://tapestry.apache.org/javascript.html
If you scroll down (or ctrl +f) to "The importJavaScriptLibrary method" - I think this may help you. It looks like the approach you are using is also documented under "Approach 1: @Import". Hope this helps, i'm new to Tapestry myself so please take what I say with a pinch of salt, but the documentation seems to show how it can be done (I believe you would just need an if statement in your page class). Thanks, Steve On 23 October 2013 07:24, lidijaldo . <lidija....@gmail.com> wrote: > I figured out the difference: > > when the if condition is met, the datatable isn't displayed. > > The HTML source has the following libraries included: > <script src="/assets/0.0.1-SNAPSHOT/ctx/js/jquery-ui-1.8.19.custom.min.js" > type="text/javascript"></script> > <script src="/assets/0.0.1-SNAPSHOT/ctx/js/TableTools.js" > type="text/javascript"></script> > <script src="/assets/0.0.1-SNAPSHOT/ctx/js/dataTables.editor.min.js" > type="text/javascript"></script> > <script src="/assets/0.0.1-SNAPSHOT/ctx/js/dataTables.editor.commons.js" > type="text/javascript"></script> > > When the if condition is NOT met, the datatable is displayed and ALSO the > tapestry libraries for datatables are included: > > <script > src="/assets/0.0.1-SNAPSHOT/jquery/assets/components/datatables/jquery.dataTables.js" > type="text/javascript"></script> > <script > src="/assets/0.0.1-SNAPSHOT/jquery/assets/components/datatables/dataTables.js" > type="text/javascript"></script> > > These 2 libraries are not included when the if condition is met and that's > why the javascript error occurs. > > Is there a way to conditionally import the below javascript libraries? > > @Import(stylesheet = { > "context:layout/datatables/css/jquery.dataTables.css", > "context:layout/datatables/css/dataTables.editor.css", > "context:layout/tabletools/css/TableTools.css" > }, > library = { > "context:js/jquery-ui-1.8.19.custom.min.js", > "context:js/TableTools.js", > "context:js/dataTables.editor.min.js", > "context:js/dataTables.editor.commons.js" > }) > > I don't want these libraries to be included when I'm not displaying the > datatable. > The second option is to include Tapestry's jquery.dataTables.js and > dataTables.js even in case when I'm not displaying the datatable. > > How can this be easily achieved? > > Regards, > Lidija > > > On Wed, Oct 23, 2013 at 7:29 AM, lidijaldo . <lidija....@gmail.com> wrote: > >> Hi, >> >> I stumbled upon the next warning a couple of times already and I still >> don't understand why I'm getting it. In our tapestry application we're >> using jquery datatables and it works ok. But in some cases the application >> starts giving me a javascript alert: *"Warning: TableTools 2 requires >> DataTables 1.9.0 or newer - www.datatables.net/download"*. >> >> In the Javascript console I see the following errors: >> >> TypeError: f.fn.DataTable is undefined >> >> ...ools:{});TableTools._aInstances.push(a);return >> a.dom.container},cFeature:"T",sFe... >> >> TableTools.js (line 76) >> TypeError: j is undefined >> >> ...(){},open:function(){},close:function(){}};f.models.field={className:"",name:nul... >> >> dataTa....min.js (line 13) >> TypeError: $.fn.dataTable is undefined >> >> editor = new $.fn.dataTable.Editor(options);// editor >> >> >> >> This is my tml file: >> >> <html t:type="layout" >> title="Modules" >> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" >> xmlns:h="tapestry-library:jquery" >> xmlns:p="tapestry:parameter"> >> >> <div class="container"> >> <br style="clear: both;" /> >> >> <t:form t:id="moduleForm" id="moduleForm" class="TTWForm >> ui-sortable" t:type="form" > >> Choose module: >> <select t:type="select" >> t:id="selectModule" >> t:model="moduleSelectModel" >> encoder="moduleSelectEncoder" >> t:value="module" >> /> >> <input type="submit" value="Submit"/> >> </t:form> >> >> <div class="clear"></div> >> </div> >> >> <t:if test="isModuleSelected"> >> <table t:type="jquery/datatable" t:id="najdiEdiDataTable" >> t:source="datasource" >> t:row="dataTableRow" t:rowIndex="index" >> t:model="sourcemodel" >> t:rowsPerPage="10" t:options="dataTableOptions" >> t:mode="true" /> >> </t:if> >> >> </html> >> >> >> ... Notice the section <t:if test=...> >> I'm trying not to display the datatable if there is no option selected via >> the dropdown menu. >> If I remove the <t:if>, there is no warning and the datatable is always >> displayed. If there is no option selected in the dropdown menu, it is >> empty, which is fine. >> >> So why the javascript error? What does the <t:if> have to do with it? >> >> Thanks in advance, >> Lidija >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org