Skip to content

Latest commit

 

History

History
229 lines (164 loc) · 5.87 KB

readme.md

File metadata and controls

229 lines (164 loc) · 5.87 KB

There are three category tags in the package:

  • Template Tags
  • Paginate Tags
  • Html Tags

Installation

Add dependency in maven to use it.

<dependency>
    <groupId>org.agilej</groupId>
    <artifactId>rtl</artifactId>
    <version>0.1-SNAPSHOT</version>
</dependency>

Templating Tags

For using RTL templating tags you need to complete three steps:

  1. tell rtl where to locate your template page
  2. define your template page
  3. use your template in every page

Locate your template file

RTL can use three ways to locate template file.

  • Default template file
WEB-INF/views/layout/template.jsp
  • Define template file in web.xml
<context-param>
    <param-name>RTLTempatePage</param-name>
    <param-value>/WEB-INF/views/layout/template.jsp</param-value>
</context-param>
  • Register customized TemplateResolver
<context-param>
    <param-name>RTLTemplateResolverClass</param-name>
    <param-value>com.your.CustomizedTemplateResolver</param-value>
</context-param>

Define your template page

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="r" uri="r-tag"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<r:yieldTitle prefix="Gloable Title | "></r:yieldTitle>

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

<r:yieldStylesheets></r:yieldStylesheets>

<script type="text/javascript" src="jquery-1.7.2.min.js" ></script>

<r:yieldJavascripts />

</head>
<body>
    <div id="body">
        <div id="sidebar">
                
        </div>
        
        <div id="main">
            <div class="content" >
                <r:yieldBody></r:yieldBody>
            </div>
        </div>
    </div>
</body>
</html>

Tags Explain

  • yieldTitle Used in template page, can set the single page's title
  • yieldStylesheets Used in template page, add the page specific style
  • yieldJavascripts `Used in template page, add the page specific javascript
  • yieldBody Used in template page, output the your templated page

Use template page.

Use the template in your every page needed to be templated. For exmaple you have a sample jsp page named sample.jsp and want to use a template.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="r" tagdir="r-tag"%>

<r:stylesheet name="/resources/styles/input.css"></r:javascript>

<r:javascript name="/resources/js/input.js"></r:javascript>

<r:layout title="title for this page">
    <h3>page title</h3>
    <ul><li>...</li></ul>   
</r:layout>

Tags Explain

  • layout Used in templated page, declare current page needs templated
  • stylesheet Used in templated page, specify one stylesheet which needed by current page
  • javascript Used in templated page, specify one javascript which needed by current page

Paginate Tags

How to use

Set the i18n resouces needed by the paginate tag, this step is required.

default.paginate.label.previous = Previous Page
default.paginate.label.next = Next Page

Use the PaginateSupportArray to wrap your normal List which will be used on the paginating page.

public List<User> listAllUsers(int page, int pageSize){
    List<User> users = // get record from database
    int total = //count from database
    PaginateSupportArray list = new PaginateSupportArray(users);
    list.setTotal(total);
    list.setPage(page);
    list.setPageSize(pageSize);
    return list;
}

Use the wrapped List in jsp

<r:paginate data="${results}" />

Customize Style

The paginate tag will generate the following html code without any specific styles, you can set styles in your css file.

<div class="pagination">
    <a href="/xxx?page=9" title="Next Page" class="label pre">Previous Page</a>
    <a href="/xxx?page=10" class="number current">10</a>  
    <span>...</span>
    <a href="/xxx?page=31" class="number">31</a>
    <a href="/xxx?page=11" title="Next Page" class="label next">Next Page</a>
</div>

Paginate Tag's attributes explain

Attribute NameRequiredUsageNote
dataYthe data list which got pagination info fromthe data object must be an instance of PaginateSupportArray
pathNcustomzied url for links in the paginationRTL will get it automaticly if it's not given.
pageVarNthe variable name which identify the page infodefault is "page"
preLabelNthe text will be displayed as the previous page link labelgot from i18n if not setted
nextLabelNthe text will be displayed as the next page link labelgot from i18n if not setted

Html Tags

  • a
  • table

Both tags support dynamic attributes like css, id ...

<r:a>

Use a tag to create html link. It's a replacement of JSTL's <c:url>

Example

<r:a class="link_a" href="/user/${user.id}">${user.login}</r:a>

<r:table> & <r:col>

RTL's table tag is a very simple solution for rendering data table. If you want more powerful solution, the Display Tag is a recommendation.

Use <r:table> and <r:col> to define a data table.

Example

<r:table data="${users}" var="user" id="tbl_1" class="table" varStatus="loop">
  <r:col headerKey="user.login.label" >
    <r:a class="link_a" href="/user/${user.id}">${user.login}</r:a>
  </r:col>
  <r:col header="Mail">${user.email}</r:col>
  <r:col header="Operation"></r:col>
</r:table>

Both table and col tag support dynamic attribute, you can customize their styles or whatever you like.

License

RTL is released under the MIT license: