I'm looking for a good way to manage CSS and JS resources using Apache Tiles in a similar way to ASP.NET MVC 4.
In ASP.NET MVC4 you have ContentBundles and ScriptBundles and you can simply write
@Scripts.Render("~/bundles/jquery");
It will insert your css/scripts with all the proper syntax. Then to make it even better there is @RenderSection("JavaScript", required:false) which allows you to insert JavaScript in the correct include order with it being defined on a view as so.
@section JavaScript
{
<script type="text/javascript" src="@Url.Content("/Scripts/jquery.tablesorter.min.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/Custom/Roster.js")"></script>
}
To make this short I basically want to do something like this in Spring MVC using Apache Tiles. Is it even possible?
My initial thought and attempt was to create a "bundle" as a definition in the tiles config file but then there needs to be some JSP code to insert and create the html syntax properly. Has anyone ever attempted this before or found a good solution?
I found this example at http://www.coderanch.com/how-to/java/TilesJavaScript but it doesn't seem to be syntactically correct for Tiles 3.
master-layout.jsp
">
Here's how you'd do it for multiple js files:
tiles-defs.xml
<!-- Child page Definition -->
<definition name="child.page" extends="master.page">
<put name="title" value="Child Page" />
<put name="jsfile" value="app.childpage.jsfiles.tile" />
</definition>
<!-- JS Files Definition tile -->
<definition name="app.childpage.jsfiles.tile" path="/layouts/jslayout.jsp">
<putList name="jsfilesList">
<add value="/config/childpage_jsfile1.js"/>
<add value="/config/childpage_jsfile2.js"/>
<add value="/config/childpage_jsfile3.js"/>
</putList>
</definition>
jslayout.jsp
<tiles:useAttribute id="list" name="jsfilesList" classname="java.util.List" />
<c:forEach var="jsfileName" items="${list}">
<script src="<%=request.getContextPath()%><c:out value='${jsfileName}' />"></script>
</c:forEach>
Essentially I want a clean way to include all my JavaScript and CSS using Apache Tiles similar to the ASP.NET MVC bundle method. This way I'm not having to hard code the links into every single JSP file that needs something additional.