cbarnes wrote:
>
> I want to be able to create a variable in a custom tag and make this
> variable available in the JSP the tag was called from.
>
> To do this I added the following line to the doStartTag (or doEndTag) method
> in the custom tag.
> pageContext.setAttribute("myvariable", myvariable,
> PageContext.APPLICATION_SCOPE);
>
> I then created a TagExtraInfo class that looked similar to the following
> (this class was added to the tld file):
>
> public class myTEI extends TagExtraInfo
> {
>     public VariableInfo[] getVariableInfo(TagData data)
>     {
>         String name = data.getAttributeString("name");
>         String type = data.getAttributeString("type);
>
>         VariableInfo[] scriptvars = new VariableInfo[1];
>         scriptvars[0] = new
> VariableInfo(name,type,true,VariableInfo.AT_BEGIN);
>
>         return scriptvars;
>     }
> }
>
> The problem with this is that in  getVariableInfo the values of name and
> type are null.
> Can anyone tell me if the problem is with the line of code where I add the
> variable to the pageContext or with the TEI class and how I can fix this?

Does your tag have required attributes named "name" and "type"? The
getAttributeString() method returns the value of the specified tag
attribute, so if the attribute is not specified, you get null.

If you want to create a variable with a fixed name and type, just
use hardcoded values for the name and the type in the VariableInfo
constructor.

Hans
--
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