RTL means R-tag library. It's a tag library for JSP.
This project is maintained by donnior
There are three category tags in the package:
Currently you need to install the artifact manually
git clone git://github.com/donnior/RTL.gitmvn installAdd dependency in maven to use it.
<dependency>
<groupId>me.donnior</groupId>
<artifactId>rtl</artifactId>
<version>0.1</version>
</dependency>
Set the template page in web.xml, make sure the param name is RTLTempatePage; if not, RTL will use the default template page which is WEB-INF/views/layout/template.jsp
<context-param>
<param-name>RTLTempatePage</param-name>
<param-value>/WEB-INF/views/layout/template.jsp</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>
Use the template in your every page needed to be templated. Like this:
<%@ 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>
Used in template page, can set the single page's title
Used in template page, add the page specific style
Used in template page, add the page specific javascript
Used in template page, output the your templated page
Used in templated page, declare current page needs templated
Used in templated page, specify one stylesheet which needed by current page
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 |
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">
<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>