JSP Custom Tag For Pagination, Sorting and Filtering - A Case Study
JSP Custom Tag For Pagination, Sorting and Filtering - A Case Study
Abstract Tag libraries have the power of reducing complex functionalities to one liners by separating out implementation part
from tag declarations. Tags do hide the implementation specific tasks from the end user by making the code more readable. The
frequently and widely used functionality in any application is database operations which involve lot of code repetition. Such a
repeated code can be hidden behind a couple of custom tags where the end user can be concerned only with the tag usage which
renders the application bug free and also aids in rapid application development. Majority of automation softwares at the minimal
incorporate functionalities for interaction with repository of data . The need for quick searching of required data and retrieving
subsets of data demand sorting, pagination, and filtering capabilities to be an integral part of any application. With the exponential
growth in data these functionalities become mandatory to be incorporated in any application irrespective of its type and size.
Further, Rich Internet Application (RIA) demands an attractive graphical user interface providing visual clues on the type of data
to be entered or to be displayed. In order to cater a solution to this issue, in the current paper, the authors have designed and
implemented a JSP custom tag for displaying a database table data in columns of different types such as check boxes, images,
hyperlinks etc. Boolean attributes are added to the tag for enabling one or more of the features corresponding to pagination,
sorting and filtering.
Keywords- BodyTagSupport, Graphical User Interface, JSP Custom Tag, Tag Attribute, Tag Library Descriptor, Tag Handler Class.
__________________________________________________*****_________________________________________________
404
IJRITCC | June 2016, Available @ http://www.ijritcc.org
________________________________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 4 Issue: 6 404 - 411
________________________________________________________________________________________________________
III. THEORETICAL FRAMEWORK FOR TAG DESIGN <tag-class></tag-class>
<body-content></body-content>
Since the tag works independent of back end database <attribute>
management system, retrieving a range of records sequentially <name></name>
poses a big challenge in implementation. Further, MS-Access .
does not support any pseudo columns as is the case with other .
back end database managements systems such as MySQL , </attribute>
Oracle etc. These systems support pseudo columns with the .
name either ROWID, or ROWNUM, depending on the system .
which makes the task easier. The authors have come up with a
query in MS-Access for sequential retrieval of records in a </tag>
specified range. .
For retrieving first N records from book table, the MS-Access .
query is <tag>
SELECT TOP N * FROM book; </tag>
</taglib>
For retrieving the records in the range N1-N2 the query can be
formulated as shown below: The required child elements of <tag> element are <name>,
<tag-class> and <body-content> and optional child element is
No of Records per Page = (N2-N1+1) <attribute>. The <attribute> child element contains the
compulsory child element <name> and other optional child
SELECT TOP <No of Records per Page> * FROM book elements such as <rtexprvalue>, <required>, etc.
WHERE <PK> not in (select TOP <N1-1> * No of Records
per Page > <PK> from book); B. Class Diagram
where <PK> refers to primary key column. Table I. depicts The structure of the various classes employed in tag design
using the query for retrieving records in different range. and interaction between them is depicted in Figure 1.
} Iterator it=columns.iterator();
while (it.hasNext())
if (backEnd==Oracle) {
{ Column c = (Column)it.next();
loadDriver(Oracle); columnName=c.getName();
connectTo(Oracle); type=c.getType();
} url=c.getUrl();
/* Construct Table Header depending on attributes specified in hyperText=c.getHyperText();
Tag */
if (allowSorting.equals("true"))
query="SELECT * FROM " + tableName; {
executeQuery(query); data+="<a href='";
if (sortColumnName != null) data+=page;
{ data+="?columnName=";
query += " ORDER BY "; data+=columnName;
query += sortColumnName; if (page != null)
} {
data+="&page=";
if (allowPaging.equals("true")) data+=pageno;
{ }
if (backEnd.equals("MS-Access")) data+="'>";
{ data+=columnName;
if (pageno==1) data+="</a>";
query="SELECT TOP " + recordsPerPage +
" * FROM " + tableName; }
408
IJRITCC | June 2016, Available @ http://www.ijritcc.org
________________________________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 4 Issue: 6 404 - 411
________________________________________________________________________________________________________
else V. RESULTS AND DISCUSSIONS
data+=columnName;
} The algorithm presented above is implemented in Java Server
Pages using Eclipse editor. The tag is tested for different
it=columns.iterator(); database management systems. Different test cases are
while (it.hasNext()) presented here.
{
Column c = (Column)it.next(); Test Case 1 : Without Sorting, Pagination and Filtering
name=c.getName(); Enabled for MySQL Database.
type=c.getType(); JSP code snippet in which sorting, pagination and filtering are
url=c.getUrl(); disabled is shown below:
query="SELECT " + name + " <%@ taglib uri="/WEB-INF/lib/customtag.tld"
FROM " + tableName + " WHERE 1 = 2 "; prefix="Database" %>
executeQuery(query); <%
} String fid=request.getParameter("fid");
if (fid == null || fid == "")
while (nextRecord()) fid="1";
{ %>
it=columns.iterator(); <html>
while (it.hasNext()) <head>
{ <title>Custom Tag for Sorting, Pagination and
Column c = (Column)it.next(); Filtering</title>
name=c.getName(); </head>
type=c.getType(); <body>
url=c.getUrl(); <h3>Sorting and Pagination</h3>
<Database:DisplayTable databaseName="library"
hyperText=c.getHyperText(); backEnd="MySQL"
if (type.equals("regular")) userName="root" password="mca"
{ tableName="book" columnNames="all"/>
data+=columnValue; </body>
} </html>
else if (type.equals("checkbox")) GUI generated by the tag is shown in Figure 3.
{
if (columnValue.equals("true"))
data+="<input type='checkbox'
checked='true'>";
else
data+="<input
type='checkbox'>";
}
else if (type.equals("image"))
{
data+="<image src='";
data+=columnValue;
data+="' height=50
width=50></img>";
}
else if (type.equals("hyperlink"))
{
data+="<a href='";
data+=columnValue;
data+="' download>";
data+=hyperText;
data+="</a>"; Figure 3. GUI Generated by the Custom Tag on Disabling Sorting,
}
Pagination and Filtering
}
}
print(data); Test Case 2 : Sorting Enabled allowSorting attribute of
} DisplayTableTag tag is set to true for MS-Access Database.
}
JSP code snippet in which sorting enabled is shown below:
409
IJRITCC | June 2016, Available @ http://www.ijritcc.org
________________________________________________________________________________________________________
International Journal on Recent and Innovation Trends in Computing and Communication ISSN: 2321-8169
Volume: 4 Issue: 6 404 - 411
________________________________________________________________________________________________________
<%@ taglib uri="/WEB-INF/lib/customtag.tld" prefix =
"Database" %>
<html>
<head>
<title>Custom Tag for Enabling Sorting</title>
</head>
<body>
<h3>Sorting, Filtering and Pagination</h3>
<Database:DisplayTable dsnName="clibrary"
tableName="book" columnNames="all"
allowSorting="true" />
</body>
</html>
411
IJRITCC | June 2016, Available @ http://www.ijritcc.org
________________________________________________________________________________________________________