title: Manage JavaScript and CSS with Apache Tiles
body: <p>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.</p>
  
  <p>In ASP.NET MVC4 you have ContentBundles and ScriptBundles and you can simply write</p>
  
  <p>@Scripts.Render("~/bundles/jquery");</p>
  
  <p>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.</p>
  
  <pre><code>@section JavaScript
  {
      &lt;script type="text/javascript" src="@Url.Content("/Scripts/jquery.tablesorter.min.js")"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="@Url.Content("/Scripts/Custom/Roster.js")"&gt;&lt;/script&gt;
  }
  </code></pre>
  
  <p>To make this short I basically want to do something like this in Spring MVC using Apache Tiles. Is it even possible?</p>
  
  <p>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?</p>
  
  <p>I found this example at <a href="http://www.coderanch.com/how-to/java/TilesJavaScript">http://www.coderanch.com/how-to/java/TilesJavaScript</a> but it doesn't seem to be syntactically correct for Tiles 3.</p>
  
  <p>master-layout.jsp</p>
  
  <p>
          ">
          
      </p>
  
  <p>Here's how you'd do it for multiple js files:</p>
  
  <p>tiles-defs.xml
              
          <br>
              <br>
              <br>
               
               
              
           </p>
  
  <pre><code>    &lt;!-- Child page Definition --&gt; 
      &lt;definition name="child.page" extends="master.page"&gt;    
          &lt;put name="title" value="Child Page" /&gt; 
          &lt;put name="jsfile" value="app.childpage.jsfiles.tile" /&gt;
      &lt;/definition&gt;
  
      &lt;!-- JS Files Definition tile --&gt;
  
      &lt;definition name="app.childpage.jsfiles.tile" path="/layouts/jslayout.jsp"&gt;
          &lt;putList name="jsfilesList"&gt;
              &lt;add value="/config/childpage_jsfile1.js"/&gt;
              &lt;add value="/config/childpage_jsfile2.js"/&gt;
              &lt;add value="/config/childpage_jsfile3.js"/&gt;
          &lt;/putList&gt;
      &lt;/definition&gt;
  </code></pre>
  
  <p>jslayout.jsp</p>
  
  <pre><code>&lt;tiles:useAttribute id="list" name="jsfilesList" classname="java.util.List" /&gt;
  &lt;c:forEach var="jsfileName" items="${list}"&gt;
      &lt;script src="&lt;%=request.getContextPath()%&gt;&lt;c:out value='${jsfileName}' /&gt;"&gt;&lt;/script&gt;
  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>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.</p>