<%@ page c" name="description">
<p><%@ page language="java" import="java.util.<em>,saar.etisalat.dto.</em>,saar.etisalat.*" pageEncoding="ISO-8859-1"%>
<%@ page contentType="text/html"%>
<%@ page import="org.apache.taglibs.datagrid.DataGridParameters"%>
<%@ page import="java.sql.*"%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/datagrid-1.0" prefix="ui" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"></p>
<pre class="prettyprint"><title>My JSP 'page.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</code></pre>
<p><title>jsp paging example in datagrid</title>
<style>
th a:link { text-decoration: none; color: black }
th a:visited { text-decoration: none; color: black }
.rows { background-color: white }
.hiliterows { background-color: pink; color: #000000; font-weight: bold }
.alternaterows { background-color: #efefef }
.header { background-color: cyan; color: #000000;font-weight: bold }</p>
<p>.datagrid { border: 1px solid #C7C5B2; font-family: arial; font-size: 9pt;
font-weight: normal }
</style>
</head>
<body>
<br><br></p>
<p><span align="center" style="padding-left:250px;font-size:20px;"></span>
<br>
<% ArrayList promptList = new ArrayList ();
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
connection=Conn.openConnection();
Announcements announce = new Announcements ();
int fromIndex, toIndex;
int tcount =0;
int perpage=4;
int tpage=0;
try {</p>
<p>preparedStatement = connection.prepareStatement("SELECT * from global_announcements");
resultSet= preparedStatement.executeQuery();
while (resultSet.next()) {
tcount++;</p>
<p>announce.setPromptId(resultSet.getString("prompt_id"));
announce.setPromptDescription(resultSet.getString("prompt_description"));
announce.setStartDate(resultSet.getString("start_date"));
announce.setEndDate(resultSet.getString("end_date"));
announce.setStatus(resultSet.getString("status"));
promptList.add(announce);
}
}
catch (SQLException sqlException) {
System.out.println("Unable to connect to batabase."+sqlException);
}finally{
Conn.closeConnection(resultSet,preparedStatement,connection);
}
fromIndex = (int) DataGridParameters.getDataGridPageIndex (request, "datagrid1");
if ((toIndex = fromIndex+4) >= promptList.size ())
toIndex = promptList.size();
request.setAttribute ("promptList", promptList.subList(fromIndex, toIndex));</p>
<p>pageContext.setAttribute("tCount", tcount);
%></p>
<p><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%String promptlist=(String)request.getAttribute("promptList"); %>
<ui:dataGrid items="<%=promptlist%>" var="prompt" name="datagrid1" cellPadding="0"
cellSpacing="0" styleClass="datagrid" >
<columns></p>
<p><column width="50">
<header value="" hAlign="left" styleClass="header"/></p>
<p></column></p>
<p><column width="200">
<header value="PromptId" hAlign="left" styleClass="header"/>
<item value="<%=announce.getPromptId()%>" hAlign="left"
styleClass="item"/></p>
<p></column>
<column width="200">
<header value="PromptDescription" hAlign="left" styleClass="header"/>
<item value="<%=announce.getPromptDescription()%>" hAlign="left" styleClass="item"/></p>
<p></column>
<column width="200">
<header value="StartDate" hAlign="left" styleClass="header"/>
<item value="<%=announce.getStartDate()%>" hAlign="left" styleClass="item"/></p>
<p></column></p>
<p><column width="100">
<header value="EndDate" hAlign="left" styleClass="header"/>
<item value="<%=announce.getEndDate()%>" hAlign="left" styleClass="item"/></p>
<p></column></p>
<p><column width="100">
<header value="Status" hAlign="left" styleClass="header"/>
<item value="<%=announce.getStatus()%>" hAlign="left" styleClass="item"/></p>
<p></column></p>
<p></columns>
<rows styleClass="rows" hiliteStyleClass="hiliterows"/>
<alternateRows styleClass="alternaterows"/></p>
<p><paging size="4" count="request.getAttribute{tCount}" custom="true" nextUrlVar="next"
previousUrlVar="previous" pagesVar="pages"/>
<order imgAsc="up.gif" imgDesc="down.gif"/>
</ui:dataGrid></p>
<table width="750" style="font-family: arial; font-size: 10pt" border=0>
<tr>
<td align="left" width="33%">
<c:if test="${previous != null}">
<a href="<c:out value="${previous}"/>">Previous</a>
</c:if>
</td>
<td align="center" width="33%">
<c:forEach items="${pages}" var="page">
<c:choose>
<c:when test="${page.current}">
<b><a href="<c:out value="${page.url}"/>"><c:out value="${page.index}"/></a></b>
</c:when>
<c:otherwise>
<a href="<c:out value="${page.url}"/>"><c:out value="${page.index}"/></a>
</c:otherwise>
</c:choose>
</c:forEach>
</td>
<td align="right" width="33%">
<c:if test="${next != null}">
<a href="<c:out value="${next}"/>">Next</a>
</c:if>
</td>
</tr>
</table>
<p></body>
</html> </p>
Hi Friend,
Please visit the following links:
http://www.roseindia.net/jsp/data-grid.shtml
http://www.roseindia.net/jsp/paging.shtml
Hope that the above links will be helpful for you.
Thanks