Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

custom tags pagination

843836Dec 8 2004 — edited May 19 2008
I am stuck in a problem and I need ur help ,I want to pass a vector to the taglib and show the data in pages.My code is working fine but everytime I call the jsp through next or prev link (cos it calls same jsp every time) it goes to the data base and makes the vector and return to taglib which I don't want.I wanted the jsp should go to database one time and the taglib do the rest, how can I avoid this.I wanted to store that vector object in session but I don't know how can store it and is it safe to store such a large object in session .
plzzzzzzz help me.
thanks in advance
here is my code

page.jsp-->

<jsp:useBean id="src" scope="session" class="search" />
<%@taglib uri="taglib.tld" prefix="ui"%>
<%
Vector vk=new Vector();
vk=src.getRes(); // here it goes to DB and fetch records in Vector
%>
<ui:pagination id="employee" scope="session" object="<%=vk%>" rowNum="3">
<ui:html rowColor="#E7C6A5" > </ui:html>
</ui:pagination>

paginationTag.java-->

public int doStartTag() throws JspException {

Object obj=null;
String sTemp;
HttpServletRequest httpReq=(HttpServletRequest)super.pageContext.getRequest();
String sURL = httpReq.getRequestURI()+httpReq.getQueryString();
sURL=parseURL(sURL);
setURL(sURL);
setSession(httpReq.getParameter("as_session_id"));
currentPage = Integer.parseInt(httpReq.getParameter(DEFAULT_PAGE_NAME));
currentPage++;

try{
obj= getObject();
if(obj == null)
return SKIP_BODY;

if(currentPage <=0)
return SKIP_BODY;

if(obj instanceof Vector)
{
setNumOfPages(((Vector)obj).size());
}
super.pageContext.setAttribute(DEFAULT_PAGE_NAME,new Integer(currentPage),1);
super.pageContext.setAttribute("getId",obj,1);

}catch(Exception e){e.getLocalizedMessage();}

return EVAL_BODY_INCLUDE;
}

html.java-->
public int doStartTag() throws JspException
{
JspWriter out = pageContext.getOut();
StringBuffer sb= new StringBuffer();
Object obj=null;
page= (paginationTag)TagSupport.findAncestorWithClass(this, paginationTag.class);

if(page!= null)
{
try{
obj= pageContext.getAttribute("getId");
currentPage= ((Integer)pageContext.getAttribute(DEFAULT_PAGE_NAME)).intValue();
if(obj instanceof Vector)
{
Vector vec= new Vector();
vec=(Vector)obj;
sb=generateHTML(vec); // here i m making the html code


if(currentPage>1)
sb.append("<a href=Search.jsp?pageNum="+(currentPage-1)+page.getURL()+">prev </a>");

sb.append("<a href=Search.jsp?pageNum="+currentPage+page.getURL()+"> next</a>");

out.print(sb.toString());

}

} catch (java.io.IOException ex) {
System.out.print(ex.getLocalizedMessage());
return SKIP_BODY;
}
}else{return SKIP_BODY;}
return EVAL_BODY_BUFFERED;

}

my tld file-->
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">



<taglib>
<tlib-version>1.2</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>Paging for data</short-name>
<uri>Paging for data</uri>
<display-name>Pagination</display-name>
<description>Paging for data</description>

<tag>
<name>pagination</name>
<tag-class>TagLibrary.paginationTag</tag-class>
<body-content>JSP</body-content>
<display-name></display-name>
<description></description>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<packagename>TagLibrary</packagename>
<extendsSupportClass>TRUE</extendsSupportClass>
<supportClass>BodyTagSupport</supportClass>
<implementsTryCatchFinally>FALSE</implementsTryCatchFinally>
<findparent>FALSE</findparent>
</tldx>
-->


<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->

</attribute>

<attribute>
<name>scope</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->

</attribute>

<attribute>
<name>type</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->

</attribute>

<attribute>
<name>object</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.Object</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->

</attribute>

<attribute>
<name>rowNum</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>

<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->
</attribute>

</tag>

<tag>
<name>html</name>
<tag-class>TagLibrary.pageHTMLTag</tag-class>
<body-content>JSP</body-content>
<display-name>show data</display-name>
<description></description>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<packagename>TagLibrary</packagename>
<extendsSupportClass>TRUE</extendsSupportClass>
<supportClass>BodyTagSupport</supportClass>
<implementsTryCatchFinally>FALSE</implementsTryCatchFinally>
<findparent>FALSE</findparent>
</tldx>
-->

<attribute>
<name>rowColor</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<javaVariable></javaVariable>
<defaultValue>yellow</defaultValue>
<IsReferenceID>FALSE</IsReferenceID>
<ReferencesTag>FALSE</ReferencesTag>
<ReferenceScope>Session</ReferenceScope>
<ReferencesTagType></ReferencesTagType>
<ReferencesTagVariable></ReferencesTagVariable>
<ReferencesTagReferentFirst>TRUE</ReferencesTagReferentFirst>
</tldx>
-->
</attribute>

<example></example>

</tag>


</taglib>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2008
Added on Dec 8 2004
17 comments
489 views