DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17316>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17316

taglib always returns null in first reocrd with pageContext.setAttribute

           Summary: taglib always returns null in first reocrd with
                    pageContext.setAttribute
           Product: Tomcat 4
           Version: 4.1.8
          Platform: PC
        OS/Version: Windows XP
            Status: UNCONFIRMED
          Severity: Normal
          Priority: Other
         Component: Jasper
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


/*
the codes work well under tomcat 4.0, but in 4.1.18 (I use now), the function 
pageContext.setAttribute in the doStartTag always return null to the jsp page. 
but the pageContext.setAttribute in the doAfterBody works, so I get the first 
record null, and the others well.
*/


// file: Region.java
package ttt;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class Region extends BodyTagSupport {

 private java.sql.ResultSet rs = null;

 public int doStartTag() throws JspException  {
  int retVal = SKIP_BODY;
  try {
   DBO db = (DBO) pageContext.findAttribute("db"); //my connection pool
   String sql = "select * from region";
   this.rs = db.select(sql);
   if (this.rs.next()) {
    pageContext.setAttribute("id", this.rs.getString("id")); //***
    pageContext.setAttribute("name", this.rs.getString("name")); //***

/*
i'd checked the return from the database with:
 pageContext.getOut().print("Hello."+this.rs.getString("name"));
it works properly.
*/

    retVal = EVAL_BODY_INCLUDE;
   }
  } catch (java.sql.SQLException ignored) {}

  return retVal;
 }

 public int doAfterBody() throws JspException  {
  int retVal = SKIP_BODY;
  try {
   if (this.rs.next()) {
    pageContext.setAttribute("id", this.rs.getString("id"));
    pageContext.setAttribute("name", this.rs.getString("name"));
    retVal = EVAL_BODY_AGAIN;
   }
  } catch (java.sql.SQLException ignored) {}
  return retVal;
 }
}


// file RegionEx.java

/*
anothe problem in extrainfo:
Cannot return the type exclude the "String", the following codes can be 
complied, but will cause a "can not complie the jsp exception" when i run the 
jsp file:
 String type = data.getAttributeString("type");
 if (type == null) type = "java.lang.Object";
  return new VariableInfo[] {
   new VariableInfo(data.getAttributeString("id"), type, true, 
VariableInfo.NESTED),
   new VariableInfo(data.getAttributeString("name"), type, true, 
VariableInfo.NESTED)
  };

so, have to return "String" for all the data type?

*/

package ttt;

import javax.servlet.jsp.tagext.*;

public class RegionEx extends TagExtraInfo {
    public VariableInfo[] getVariableInfo(TagData data) {
        return new VariableInfo[] {
            new VariableInfo("id", "String", true, VariableInfo.NESTED),
            new VariableInfo("name", "String", true, VariableInfo.NESTED),
        };
    }
}

//the jsp page.

<table>
<ttt:region>
<tr><td><%= name %></td><td><%= id %></td></tr>
</ttt:region>
</table>

// the 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>ttt</short-name>

        <tag>
                <name>region</name>
                <tag-class>ttt.Region</tag-class>
                <tei-class>ttt.RegionEx</tei-class>
                <body-content>JSP</body-content>
        </tag>

</taglib>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to