You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Collins, Jim" <ji...@nomura.co.uk> on 2001/02/02 11:38:36 UTC

Problem with tags that set scripting variables

Hi,

I have writen a very simple tag and jsp, what I want to do is set a
scripting variable in the tag. Below is the jsp, taglib, and tag handler.
When I try and run the jsp it throws a JasperException saying that test is
an undefined variable. I have looked at the generated code and I can see
that the variable is out of scope when I use it in the script but I don't
know how to give it scope throughout the page. Any help with this would be
greatly appreciated as I am pulling my hair out trying to figure out how to
get it to work.

Thanks.

Jim.

//the jsp file
<%@ page language="java" import="java.util.Date" %>
<html>
<head>
<title>Test</title>
</head>
<body>
<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" prefix="mars"
%>
<mars:id cp_name="test"/>
<%= test %>
</body>
</html>


//the taglib
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
        "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<!-- a tag library descriptor -->

<taglib>
  <!-- after this the default space is
        "http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd"
   -->
  <tlibversion>1.0</tlibversion>
  <jspversion>1.1</jspversion>
  <shortname></shortname>

  <!-- mars dets -->
  <tag>
    <name>id</name>
    <tagclass>UK.co.nomura.mars.utils.MarsDets</tagclass>
    <teiclass>UK.co.nomura.mars.utils.MarsDetsExtraInfo</teiclass>
    <bodycontent>empty</bodycontent>
    <info>
    </info>
    <attribute>
      <name>cp_name</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>
</taglib>


//the tag handler
public class MarsDets extends TagSupport{

  public void setCp_name(String name){
    this.cp_name = name;
  }

  public String getCp_name(){
    return cp_name;
  }

  public int doStartTag() throws JspTagException {
      pageContext.setAttribute(cp_name, "test");
      return SKIP_BODY;
  }
 public int doEndTag() throws JspTagException{
    return EVAL_PAGE;
  }
 private String cp_name;
}


PLEASE READ: The information contained in this e-mail is confidential
and intended for the named recipient(s) only. If you are not an intended
recipient of this email you must not copy, distribute or take any
further action in reliance on it and you should delete it and notify the
sender immediately. Email is not a secure method of communication and
Nomura International plc cannot accept responsibility for the accuracy
or completeness of this message or any attachment(s).  Please check this
e-mail for virus infection, for which Nomura International plc accepts
no responsibility. If verification of this email is sought then please
request a hard copy. Unless otherwise stated any views or opinions
presented are solely those of the author and do not represent those of
Nomura International plc. This email is intended for informational
purposes only and is not a solicitation or offer to buy or sell
securities or related financial instruments. Nomura International plc is
regulated by the Securities and Futures Authority Limited and is a
member of the London Stock Exchange.