Andrew Luca Andrew Luca - 1 month ago 10
HTML Question

How to achieve this layout using apache tiles 2?

enter image description here

Having problems creating such a layout. Controllers trigger dash content, and the layout should be created. Now I have this definitions, and I am blocked.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

<definition name="masterLayout" template="/WEB-INF/jsp/layout/master.jsp">
<put-attribute name="headerInclude" value="" />
<put-attribute name="body" value="" />
<put-attribute name="footerInclude" value="" />
</definition>

<definition name="dashboardLayout" extends="masterLayout">
<put-attribute name="body" value="dashboardLayoutBody" />
</definition>

<definition name="dashboardLayoutBody" template="/WEB-INF/jsp/layout/dashboard.jsp">
<put-attribute name="menu" value="/WEB-INF/jsp/parts/menu.jsp" />
<put-attribute name="body"/>
</definition>

<!-- this page is triggered -->
<definition name="login_page" extends="masterLayout">
<put-attribute name="body" value="/WEB-INF/jsp/layout/login.jsp" />
</definition>

<!-- this page is triggered -->
<definition name="some_page" extends="dashboardLayout">
<put-attribute name="body" value="/WEB-INF/jsp/content/admin_groups/supervisor.jsp"/>
</definition>

</tiles-definitions>


master layout has this content

<!DOCTYPE html>
<html>
<head>
<!-- Master css, js, meta, tags additions .... -->
<tiles:insertAttribute name="headerInclude"/>
</head>
<body>
<tiles:insertAttribute name="body"/>

<!-- Master css, js, meta, tags additions .... -->
<tiles:insertAttribute name="footerInclude"/>
</body>
</html>


I need somehow to extend template and also have own template, to include menu there

Answer

As a new comer to jsp templating, I didn't realized that I can use jsp:include in parallel with Aapache Tiles, which solved the problem.

The main problem was that I couldn't include the menu once only in the dashboard layout, and be used everywhere.

Using only tiles, there is cascade attribute on a put-attribute tag that allow that to be used in other attributes also.

Keep in mind that cascade needs DOCTYPE tiles-definition minimum version 2.1

<!DOCTYPE tiles-definitions PUBLIC
        "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
        "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
Comments