Git Product home page Git Product logo

jsp-template-inheritance's Introduction

JSP Template Inheritance

kr.pe.kwonnam.jspMaven Central

With these template inheritance tag library you can manage template layouts.

You don't need to use layout frameworks like Sitemesh or Apache Tiles.

If you use freemarker, refer to freemarker-template-inheritance.

From 0.3.RELEASE, you can download this library from the maven central repository.

Gradle dependencies

dependencies {
    compile 'kr.pe.kwonnam.jsp:jsp-template-inheritance:0.3.RELEASE'
}

Maven dependencies

<dependency>
    <groupId>kr.pe.kwonnam.jsp</groupId>
    <artifactId>jsp-template-inheritance</artifactId>
    <version>0.3.RELEASE</version>
    <scope>compile</scope>
</dependency>

Usage

web.xml

<!-- jsp-inheritance-prefix, jsp-inheritance-suffix can be omitted.-->

<context-param>
    <param-name>jsp-inheritance-prefix</param-name>
    <param-value>/WEB-INF/layouts/</param-value>
</context-param>

<context-param>
    <param-name>jsp-inheritance-suffix</param-name>
    <param-value>.jsp</param-value>
</context-param>

/WEB-INF/layouts/base.jsp : layout

<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>JSP Template Inheritance</title>
    </head>

<h1>Head</h1>
<div>
    <layout:block name="header">
        header
    </layout:block>
</div>

<h1>Contents</h1>
<div>
    <p>
    <layout:block name="contents">
        <h2>Contents will be placed under this h2</h2>
    </layout:block>
    </p>
</div>

<div class="footer">
    <hr />
    <a href="https://github.com/kwon37xi/jsp-template-inheritance">jsp template inheritance example</a>
</div>
</html>

view.jsp : contents

<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%>
<layout:extends name="base">
    <layout:put block="header" type="REPLACE">
        <h2>This is an example about layout management with JSP Template Inheritance</h2>
    </layout:put>
    <layout:put block="contents">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porta,
        augue ut ornare sagittis, diam libero facilisis augue, quis accumsan enim velit a mauris.
        Ut eleifend elit ante, sit amet suscipit leo lobortis eu. Quisque vitae lorem feugiat,
        lacinia nulla eu, interdum eros. Ut dignissim tincidunt nisl ac iaculis.
        Praesent consectetur arcu vitae tellus scelerisque venenatis.
        Morbi vel leo eros. In id libero ultricies, laoreet enim et, tempor magna.
        Vestibulum lorem velit, accumsan id purus at, lobortis fermentum diam.
        Aenean nec placerat elit. Aenean vel sem arcu.
    </layout:put>
</layout:extends>

PutType

  1. APPEND : The put contents will be appended after block's contents. default.
  2. PREPEND : The put contents will be prepended before block's contents.
  3. REPLACE : The put contents will replace block's contents. The block's contents will be removed.

PutType vlaues are case insensitive.

Layout path prefix/suffix

In web.xml you can set jsp-inheritance-prefix and jsp-inheritance-suffix context parameters. The layout name will be prefixed and suffixed with these parameters.

When you set jsp-inheritance-prefix as /WEB-INF/layouts/, jsp-ineheritance-suffix as .jsp and call <layout:extends name='base'> the layout file URL will be /WEB-INF/layouts/base.jsp.

The prefix and suffix can be omitted.

Example

example module is web application layout example. Run the module and browse http://localhost:8080/index.jsp. Refer to index.jsp, WEB-INF/layouts/base.jsp, WEB-INF/layouts/secondLayout.jsp.

Known problems

  1. If you want to pass a variable from a child page to it's layout page, the variable must be added to REQUEST scope.

Project Development

Intellij

./gradlew cleanIdea idea

Eclipse

./gradlew cleanEclipse eclipse

Reference

  1. freemarker-template-inheritance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.