There are three category tags in the package:
- Template Tags
- Paginate Tags
- Html Tags
Add dependency in maven to use it.
<dependency>
<groupId>org.agilej</groupId>
<artifactId>rtl</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
For using RTL
templating tags you need to complete three steps:
- tell
rtl
where to locate your template page - define your template page
- use your template in every page
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>
<%@ 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>
yieldTitle
Used in template page, can set the single page's titleyieldStylesheets
Used in template page, add the page specific styleyieldJavascripts
`Used in template page, add the page specific javascriptyieldBody
Used in template page, output the your templated 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>
layout
Used in templated page, declare current page needs templatedstylesheet
Used in templated page, specify one stylesheet which needed by current pagejavascript
Used in templated page, specify one javascript which needed by current page
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}" />
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>
Attribute Name | Required | Usage | Note |
---|---|---|---|
data | Y | the data list which got pagination info from | the data object must be an instance of PaginateSupportArray |
path | N | customzied url for links in the pagination | RTL will get it automaticly if it's not given. |
pageVar | N | the variable name which identify the page info | default is "page" |
preLabel | N | the text will be displayed as the previous page link label | got from i18n if not setted |
nextLabel | N | the text will be displayed as the next page link label | got from i18n if not setted |
- a
- table
Both tags support dynamic attributes like css, id ...
Use a
tag to create html link. It's a replacement of JSTL's <c:url>
<r:a class="link_a" href="/user/${user.id}">${user.login}</r:a>
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.
<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.
RTL is released under the MIT license: