Can anybody tell me why I am getting the 'Undefined variable: name' error in my JSP for the following code running on orion server: hello.jsp: --------------------------------------------------- <%@ taglib uri="mytags" prefix="mt" %> <HTML> <HEAD> <TITLE>Hello!</TITLE> </HEAD> <mt:hello> Inside the body of the tag <%=name%> </mt:hello> <%=name%> (THIS name NOT BEING IDENTIFIED BY THE JSP) </BODY> </HTML> HelloTagExtraInfo.java: ------------------------------------------------------ import javax.servlet.jsp.tagext.*; public class HelloTagExtraInfo extends TagExtraInfo { public HelloTagExtraInfo() { super(); } public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo( "name", "java.lang.String", true, VariableInfo.AT_BEGIN)}; } } HelloTag.java: ---------------------------------------------------- import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.util.*; public class HelloTag extends TagSupport { public HelloTag() { super(); } public int doStartTag() throws JspTagException { pageContext.setAttribute("name", "chris"); return EVAL_BODY_INCLUDE; } public int doEndTag() throws JspTagException { return EVAL_PAGE; } } taglib.tld: -------------------------------------------------------- <?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"> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>mt</shortname> <tag> <name>hello</name> <tagclass>com.chris.tag.HelloTag</tagclass> <teiclass>com.chris.tag.HelloTagExtraInfo</teiclass> <bodycontent>JSP</bodycontent> <info>A simple hello</info> </tag> </taglib> It works fine if I remove the name expression outside the tag body in the JSP page. TIA - Chris
Cameron Park
Ranch Hand
Joined: Apr 06, 2001
Posts: 371
posted
0
The scope for a variable defined in a TagExtraInfo is NESTED by default. In other words, it is not accessible after the particular closing tag unless you explicitly define it otherwise.
ken chou
Ranch Hand
Joined: Feb 08, 2001
Posts: 68
posted
0
On your jsp page, you need to declare the varable "name" like the following: <%! String name = null; %>
Chris Salivar
Ranch Hand
Joined: May 25, 2001
Posts: 34
posted
0
Cameron, I have declared the scope of the variable to be AT_BEGIN so its not the default one. Ken, declaring a variable in the JSP page would beat the purpose of using custom tags because we don't want to use java code in the JSP page. Is it some other problem? Anybody? TIA -Chris
Simon Brown
sharp shooter, and author
Ranch Hand
Joined: May 10, 2000
Posts: 1860
posted
0
It should work with a scope of AT_BEGIN. Which server are you using? Cheers Simon ------------------ Simon Brown Co-author of Professional JSP 2nd Edition
Chris Salivar
Ranch Hand
Joined: May 25, 2001
Posts: 34
posted
0
Thanks Simon, it magically started working when i woke up in the morning and tried it again. BTW I am using the orion server. - Chris