I'm having a hard time with Tiles.
I have a webapp with many views, all of these are composed around a single template. The template has about three or four "placeholders", and for each view, different, dynamically generated content should be placed in the correct placeholder.
When I define a new view with Tiles I need to create multiple JSP file - each with a placeholder's content. Then I need to update a huge XML file that has a lot of entries that look just the same.
I'm looking for a solution that'll allow me to declare all these placeholder's content in the same file, and partially include this file into the template (every fragment to its placeho开发者_C百科lder).
I was looking at Velocity and FreeMarker as well, but either of these doesn't seem to have a partial-include feature.
What are my options here? I'm willing to consider a change of framework just to make it a little less tedious to create yet another view.
Thanks!
I believe the reason why your xml file is huge is because you might not have extended the default template as follow
This should be your base template:
<definition name="app.base" template="/WEB-INF/templates/default.jsp">
<put-attribute name="title" value="Not Found" />
<put-attribute name="header" value="/WEB-INF/tiles/header.jsp" />
<put-attribute name="body" value="/WEB-INF/tiles/body.jsp" />
<put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" />
<put-list-attribute name="stylesheets">
<add-attribute value="/static/public/css/bootstrap.min.css" />
<add-attribute value="/static/protected/css/header.css" />
<add-attribute value="/static/protected/css/footer.css" />
</put-list-attribute>
<put-list-attribute name="javascripts">
<add-attribute value="/static/public/js/jquery-2.1.4.min.js" />
<add-attribute value="/static/public/js/bootstrap.js" />
</put-list-attribute>
</definition>
Now that you have a basic template you can EXTEND it as follow:
<definition name="home" extends="app.base">
<put-attribute name="title" value="Home Page" />
<put-attribute name="body" value="/WEB-INF/tiles/home.jsp" />
<put-list-attribute name="stylesheets" inherit="true">
<add-attribute value="/static/protected/css/whatever.css" />
</put-list-attribute>
</definition>
This new page is going to include both css stylesheets of the app base and the home page
Is this of help?
精彩评论