Nauman Rafique wrote:
>
> Hi,
> I am using my custom tag to add an attribute in the page context. I want to
> use this attribute as a script variable in my page. In my tag, i increment
> this variable and my tag iterate and display this variable. But the value of
> the variable is not incremented even though i add the incremented value in
> page context too. It displays the value i added in the context first (not
> the incremented value).

At a quick glance, your tag handler code looks okay to me. It may be a bug in
the JSP container you're using. Try using VariableInfo.NESTED instead of
VariableInfo.AT_BEGIN. Both should work, but NESTED is more common for this
type of tag handler, so a bug related to AT_BEGIN may not have been discovered
by the container developers.

Hans


> I am using a session EJB which is added in page context by another tag. The
> name of bean is counter. The method increment() increment the internal
> variable of EJB and return the value of count which is then stored in local
> variable count and added in page context.
>
> The code of my tag hanlder is
>
> package jsptoejb;
>
> import javax.ejb.EJBObject;
> import javax.servlet.jsp.*;
> import javax.servlet.jsp.tagext.*;
> import countejb.*;
>
> public class Iterator extends BodyTagSupport
> {
>     private int maxcount;
>     CountRemote counter;
>
>     public void setIterationCount(String count1)
>     {
>         maxcount = Integer.parseInt(count1);
>     }
>
>     public int doStartTag() throws JspTagException
>     {
>         int count;
>         try
>         {
>         counter =
> (countejb.CountRemote)super.pageContext.getAttribute("EJBObject");
>         count = counter.getcount();
>
>         //Here I first set the attribute
>         pageContext.setAttribute("count", new Integer(count));
>         return EVAL_BODY_TAG;
>         }
>         catch(Exception e)
>         {
>           throw new JspTagException(e.toString());
>         }
>     }
>
>     public void doInitBody()
>     {
>     }
>
>     public int doAfterBody()
>         throws JspTagException
>     {
>
>         try
>         {
>             int count = counter.getcount();
>             BodyContent body = getBodyContent();
>             if( count< maxcount)
>             {
>                 body.println("  In do after body" + count);
>                     count = counter.increment();
> // Here i again set the attribute
>                 pageContext.setAttribute("count", new Integer(count));
>                 return EVAL_BODY_TAG;
>             }
>             else
>             {
>                 body.writeOut(getPreviousOut());
>                 return SKIP_BODY;
>             }
>         }
>         catch(Exception e)
>         {
>             throw new JspTagException(String.valueOf(String.valueOf((new
> StringBuffer("The exception ")).append(e).append("was thrown"))));
>         }
>     }
>
>     public int doEngTag()
>         throws JspTagException
>     {
>         try
>         {
>             counter.remove();
>         }
>         catch(Exception e)
>         {
>             throw new JspTagException(e.toString());
>         }
>         return EVAL_PAGE;
>     }
> }
>
> And the code of my jsp is
>
> <%@ page import="countejb.*, jsptoejb.*,javax.naming.* " %>
> <HTML>
>   <HEAD>
>     <TITLE>
>       SampleJsp
>     </TITLE>
>   </HEAD>
> <BODY>
>   <H1>
>     Jsp to play with EJBs
>   </H1>
>
>   <%@ taglib uri="taglib.tld" prefix="ejb"%>
>   The trace of the program is printed here
>   <ejb:getejb nick="mycounter" initialCount="5">
>     <ejb:iterate>
>   The current value of count is <%=count>
>     </ejb:iterate>
>   </ejb:getejb>
>
> </BODY>
> </HTML>
>
> The code of my extra info class is
>
> package jsptoejb;
>
> import javax.servlet.jsp.tagext.*;
>
> public class IteratorExtraInfo extends TagExtraInfo
> {
>   public VariableInfo[] getVariableInfo(TagData data)
>   {
>   //  System.out.println("I am being used");
>     return new VariableInfo[]
>                             {
>                               new
> VariableInfo("count","Integer",true,VariableInfo.AT_BEGIN)
>                             };
>   }
> }
>
> Here is the corresponding entry in tag library descriptor:
>
> <tag>
>                 <name>iterate</name>
>                 <tagclass>jsptoejb.Iterator</tagclass>
>                 <teiclass>jsptoejb.IteratorExtraInfo</teiclass>
>                 <bodycontent>JSP</bodycontent>
>                 <attribute>
>                         <name>iterationCount</name>
>                         <required>true</required>
>                 </attribute>
> </tag>
>
> Plz find the bug and tell me ...
> Thanks in advance
>
> Nauman

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to