Jade Sitetree - Layout Tag Library

Jade Sitetree - Layout Tag Library
Project Documentation
Module Documentation
Jade Projects

Usage

This page describes some of the uses of the Layout Tag Library. Two illustrations are provided: one explaining straight-forward tag usage and a second explaining the use of the scripting variables. These and other examples can be found in the example.war file. See the example instructions for details.

Using Tags

Template
Page
Assume that this jsp page is "/templates/a_template.jsp".
<%@ taglib uri="/djinnsoft/jade/layout.tld" prefix="layout" %>

<layout:template>
    Inside the template A.<br />

    <table>
        <tr>
            <td colspan="2"><layout:display fragmentName="header"/></td>
        </tr>
        <tr>
            <td><layout:display fragmentName="sentence_a"/></td>
            <td><layout:display fragmentName="sentence_b"/></td>
        </tr>
        <tr>
            <td colspan=2><layout:display fragmentName="footer"/></td>
        </tr>
    </table>

    Template A is done.<br />
</layout:template>
Jsp
Page
<%@ taglib
    uri="/djinnsoft/jade/layout.tld"
    prefix="layout" %>

<html>
<head><title>
    Testing The Layout Manager
</title></head>
<body>

<h1>
    Testing The Layout Manager
</h1>

Before layout<br />
<layout:layout
    templateUri="/templates/a_template.jsp">

    <layout:define fragmentName="header">
        <h1>This is the Header</h1>
    </layout:define>

    <layout:define fragmentName="sentence_a">
        <p>This is the Sentence A</p>
    </layout:define>

    <layout:define fragmentName="sentence_b">
        <p>This is the Sentence B</p>
    </layout:define>

    <layout:define fragmentName="footer">
        <h1>This is the Footer</h1>
    </layout:define>

</layout:layout>
After layout<br />
</body>
</html>
<%@ taglib
    uri="/djinnsoft/jade/layout.tld"
    prefix="layout" %>

<html>
<head><title>
    Testing The Layout Manager
</title></head>
<body>

<h1>
    Testing The Layout Manager
</h1>

Before layout<br />
<layout:layout
    templateUri="/templates/a_template.jsp">

    <layout:define fragmentName="footer">
        <h1>Place this at the bottom</h1>
    </layout:define>

    <layout:define fragmentName="header">
        <h1>Place this at the top</h1>
    </layout:define>

    <layout:define fragmentName="sentence_b">
        <p>Place this on the right</p>
    </layout:define>

    <layout:define fragmentName="sentence_a">
        <p>Place this on the left</p>
    </layout:define>

</layout:layout>
After layout<br />
</body>
</html>
HTML
Result
<html>
<head><title>
    Testing The Layout Manager
</title></head>
<body>

<h1>
    Testing The Layout Manager
</h1>

Before layout<br />
Inside the template A.<br />

<table>
    <tr><td colspan="2">
        <h1>
            This is the Header
        </h1>
    </td></tr>
    <tr>
        <td><p>
            This is the Sentence A
        </p></td>
        <td><p>
            This is the Sentence B
        </p></td>
    </tr>
    <tr><td colspan=2>
        <h1>
            This is the Footer
        </h1>
    </td></tr>
</table>

Template A is done.<br />
After layout<br />
</body>
</html>
<html>
<head><title>
    Testing The Layout Manager
</title></head>
<body>

<h1>
    Testing The Layout Manager
</h1>

Before layout<br />
Inside the template A.<br />

<table>
    <tr><td colspan="2">
        <h1>
            Place this at the top
        </h1>
    </td></tr>
    <tr>
        <td><p>
            Place this on the left
        </p></td>
        <td><p>
            Place this on the right
        </p></td>
    </tr>
    <tr><td colspan=2>
        <h1>
            Place this at the bottom
        </h1>
    </td></tr>
</table>

Template A is done.<br />
After layout<br />
</body>
</html>

Using the Scripting Variables

This example illustrates the use of the layout and fragment scripting variables inside the template file. Assume that an unknown number of ArticleTestRecs were inserted into the layout in the JSP page. The template file below will display them in a table. The scripting variables "layout" and "fragment" have been emphasized.

Template
Page
<%@ taglib uri="/djinnsoft/jade/layout.tld" prefix="layout" %>

<%@ page import="com.djinnsoft.jade.layout.ArticleTestRec" %>
<%@ page import="java.util.Iterator" %>

<layout:template>
    Inside the template b.<br />

    <table border="1">
    <%
        Iterator it = layout.getFragmentIds().iterator();
        while( it.hasNext() ) {
    %>
            <layout:display fragmentId='<%=(Integer)it.next()%>'>
                <tr>
                    <td><%= ((ArticleTestRec)fragment).getTitle() %></td>
                    <td><%= ((ArticleTestRec)fragment).getDeck () %></td>
                </tr>
            </layout:display>
    <%
        }
    %>
    </table>

    Template b is done.<br>
</layout:template>


Supported by SourceForge.net Logo