Hi
I have created a tag class for the same.
I am attaching the code
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.log4j.Category;
public class ShowPagescrollsTag extends TagSupport {
static Category cat = Category.getInstance("vaa");
int length=-1; //No of rows per page
Integer total; //The size of the collection to be displayed
int pageIndex = 1; //The page on display currently
//int pageRange = 10; //No of pages displayed on the scroll bar
String paramName="";
String paramValue="";
boolean error = false;
String errorCommon = "ShowPageScrollsTag ERROR:";
String errorMessage;
String context = "";
public Integer getTotal()
{
return total;
}
public int getLength()
{
return length;
}
public String getParamName()
{
return paramName;
}
public String getParamValue()
{
return paramValue;
}
public void setTotal(Integer total)
{
this.total = total;
}
public void setLength(int length)
{
this.length = length;
}
public void setParamName(String paramName)
{
this.paramName = paramName;
}
public void setParamValue(String paramValue)
{
this.paramValue = paramValue;
}
public int doEndTag() throws JspException
{
if(!error)
{
return EVAL_PAGE;
}
else
{
throw new JspException(errorCommon + errorMessage);
}
}
/**
* Generates the pagination section.
* @param Integer
* @param Integer total - representing how many result sets have to be shown in all
* @param
*/
public int doStartTag() throws JspException
{
HttpServletRequest request;
int numPages,startPage,endPage;
//int tempStart;
pageIndex = 1;
startPage = 1;
int total = this.total.intValue();
String uri;
//If length is not set, it is assumed
//to have been specified in the tgt:iterate tag.
length = (length == -1)?((Integer)pageContext.getAttribute("length")).intValue():length;
if(total < 0)
{
error = true;
errorMessage = "Attribute total should have a positive integer value!";
return SKIP_BODY;
}
if(total == 0)
{
return SKIP_BODY;
}
if(length <=0)
{
error = true;
errorMessage = "Attribute length should have a positive non-zero integer value!";
return SKIP_BODY;
}
numPages = (total%length == 0)?(total/length):(total/length+1);
StringBuffer contents = new StringBuffer();
if(numPages > 1)
{
request = (HttpServletRequest)pageContext.getRequest();
context = request.getContextPath();
if(request.getParameter("offset") != null)
{
pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
startPage = Integer.parseInt(request.getParameter("startPage"));
}
//Find the request URL, we have to use it again
uri = request.getRequestURI();
contents.append("
");
contents.append("
Page " + Integer.toString(pageIndex) + " of " + Integer.toString(numPages) + "");
cat.debug("Showing Page " + pageIndex + " of " + numPages);
contents.append(" ");
if(pageIndex == 1)
{
contents.append("

");
contents.append(" ");
contents.append("

");
}
else
{
contents.append("

");
contents.append(" ");
int prevPage = pageIndex - 1;
int prevOffSet = (prevPage -1)*length;
if(prevPage < startPage)
{
startPage--;
}
contents.append("

");
}
contents.append(" ");
if(pageIndex == numPages)
{
contents.append("

");
contents.append(" ");
contents.append("

");
}
else
{
int nextPage = pageIndex + 1;
int nextOffSet = (nextPage - 1) * length;
contents.append("

");
contents.append(" ");
int lastOffSet = (numPages-1) * length;
contents.append("

");
}
contents.append("
");
} //End of numPages gt 1 check
//cat.debug(contents);
JspWriter out = pageContext.getOut();
try{
out.println(contents.toString());
}
catch(IOException ie)
{
error = true;
errorMessage = ie.getLocalizedMessage();
}
return SKIP_BODY;
}
}