Include part of tile with Apache slabs?

It's hard for me with Tiles.

I have a webapp with many views, all of them are made around one template. A template contains about three or four β€œplaceholders,” and for each view, another, dynamically generated content must be placed in the correct placeholder.

When I define a new view with Tiles, I need to create several JSP files - each with placeholder content. Then I need to update a huge XML file that has a lot of records that look the same.

I am looking for a solution that will allow me to declare the entire contents of this placeholder in the same file and partially include this file in the template (each fragment to its placeholder).

I also looked at Velocity and FreeMarker, but none of them seem to have a partial inclusion feature.

What are my options here? I am ready to consider a change in structure to make it a little less tiring to create another view.

Thanks!

+4
source share
1 answer

I believe the reason your XML file is huge is because you might not have expanded the default template by following

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 the basic template, you can EXTEND it as follows:

 <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 will contain both CSS stylesheets for the application database and the home page.

Did it help?

0
source

All Articles