Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 153477 - JSP Editor does not recognise custom tag library
Summary: JSP Editor does not recognise custom tag library
Status: CLOSED DUPLICATE of bug 87143
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: jst.jsp (show other bugs)
Version: 1.5   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Nitin Dahyabhai CLA
QA Contact: David Williams CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-10 14:26 EDT by Mi Amidot CLA
Modified: 2006-11-28 15:51 EST (History)
0 users

See Also:


Attachments
Squiggy underline (36.34 KB, image/jpeg)
2006-08-29 14:49 EDT, Mi Amidot CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mi Amidot CLA 2006-08-10 14:26:37 EDT
Here is a simple JSP, z.jsp using my custom jsp tag lib:

===================================================
<%@taglib uri="/WEB-INF/text-taglib.tld" prefix="z"%>
<z:text id='a1' scope='page'>
How much crap could a crap crab grab
if a crap crab crept and grabbed its crap.
</z:text>

<%=a1%>
===================================================
The tag library simply creates a scope attribute of a StringBuffer.
Where its id (in this case: a1 ) is projected by jsp processor as an automatic variable of the same name and of type Stringbuffer. 

**This tag lib is useful for enveloping huge chunks of SQL, HTML or SAS code by averting the ugly String sql = "xxxx" + "xxxx" to construct multiline text.***

z.jsp runs without error on tomcat5.5 attached to Eclipse, providing expected output on IE.

However, JSP Editor croaks by underlining "a1" with red squigy line,
error icon complaining "no end tag </z>",
and error message "a1 cannot be resolved".

Unless requested, I don't think I need to include tag lib java code and tld since I verified z.jsp runs error free on eclipse/tomcat and netbeans/tomcat.
Comment 1 Nitin Dahyabhai CLA 2006-08-22 00:05:59 EDT
The more useful information, the better.

It's underlining the "a1" attribute value in the z:text start tag saying that a1 can not be resolved?
Comment 2 Mi Amidot CLA 2006-08-29 14:49:22 EDT
Created attachment 48991 [details]
Squiggy underline

Notice the squiggy underline? Implying that JSP editor does not parse the TLD of custom tags.
Comment 3 Mi Amidot CLA 2006-08-29 15:04:05 EDT
Even after installing MyEclipse 5 Pro (latest), Eclipse failed to resolved attribute variables.

JSP editor needs to parse TLD and then locate the relevant java class encoding the JSP tag. 

If you have used Netbeans and are familiar with custom jsp tags, you would know what I mean.

In case Eclipse team is not familiar with custom jsp tags ...

A JSP programmer invokes a tag:

<aprefix:whatever id='a1' scope='page'>
'allo 'allo
</aprefix:whatever >

JSP parser/compiler would generate code to:
1. insert tag body "'allo 'allo" into page(depending on declared scope) attribute value with "a1" as attribute key.
2. spontaneously declare a variable (or in JSP, terminology automatic variable). The spontaneous/automatic variable has the type defined by the TEI class. Therefore, jsp editor needs to inquire TEI class method getVariableInfo to seamlessly present that variable to the JSP programmer and J2EE server.

This is how a TLD would look like. Notice the java class of the tag is specified as tagclass:

<?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>mycompany</shortname>
 <uri>/WEB-INF/text-taglib.tld</uri>

	<tag>
		<name>text</name>
		<tagclass>com.mycompany.jsp.taglibs.Text.TextTag</tagclass>
		<teiclass>com.mycompany.jsp.taglibs.Text.TextTEI</teiclass>
		<bodycontent>JSP</bodycontent>
		<attribute>
			<name>id</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>ref</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>debug</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>scope</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
		<attribute>
			<name>display</name>
			<required>false</required>
			<rtexprvalue>true</rtexprvalue>
		</attribute>
	</tag>

</taglib>


Then the tag class java code would be like this:
package com.mycompany.jsp.taglibs.Text;

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

public class TextTag
extends BodyTagSupport
{
    public void setId(String value)
    {
        id = value;
    }
    
    public String getId()
    {
        return (id);
    }
    
    public void setRef(String value)
    {
        ref = ("" + value).trim();
    }
    
    public String getRef()
    {
        return (ref);
    }
    
    public void setDebug(String value)
    {
        String s = ("" + value).trim().toLowerCase();
        if (s.equals ("true"))
            debug=true;
        else if(s.equals ("false"))
            debug=false;
    }
        
    public void setDisplay(String value)
    {
        String s = ("" + value).trim().toUpperCase();
        if(s.equals("TRUE")) display=true;
    }
    
    
    public void setScope(String value)
    {
        scope = ("" + value).trim().toUpperCase();
        
        if (scope.equals("SESSION"))
            _scope = PageContext.SESSION_SCOPE;
        else if (scope.equals("APPLICATION"))
            _scope = PageContext.APPLICATION_SCOPE;
        else if (scope.equals("PAGE"))
            _scope = PageContext.PAGE_SCOPE;
        else if (scope.equals("REQUEST"))
            _scope = PageContext.REQUEST_SCOPE;
    }
    
    public int doStartTag()
    {
        if (ref != null )
        {
            Object o = pageContext.getAttribute(ref, _scope);
            /* o.getclass is pointless code but Bug in j1.4.0 needs 
             * getClass to trigger proper working of "instanceof" */
            body = (o!=null && o.getClass()!=null && o instanceof StringBuffer)
            ?(StringBuffer)o:new StringBuffer();
        }
        else
        {
            ref = "";
            body = new StringBuffer();
        }
        
        String name = (id==null || id.length()==0)
        ?ref:id;
        pageContext.setAttribute(name, body, _scope);
        
        return EVAL_BODY_BUFFERED;
    }
    
    public int doEndTag()
    {
        if(display)
        {
            try
            {
                bodyContent.getEnclosingWriter().write(body.toString());
            }
            catch (IOException ex)
            {
                System.out.println("text display failure:" + ex);
            }
        }
        return EVAL_PAGE;
    }
    
    public int doAfterBody()
    throws JspTagException
    {
        //	pageContext.setAttribute(id, this, _scope);
        String s = readBody();
        if(s!=null)
            body.append(s);
        
        if (debug)
            System.out.println("text body:" + body);
        
        return SKIP_BODY;
    }
    
    String readBody()
    {
        BodyContent bc = getBodyContent();
        if (bc == null)
            return null;
        String s = bc.getString();
        bc.clearBody();
        return s;
    }
    
    public String toString()
    {
        return body.toString();
    }
    
    public void setBody(String value)
    {
        body = new StringBuffer(value);
    }
    
    public StringBuffer getBody(String value)
    {
        return body;
    }
    
    String scope = null;
    int _scope = PageContext.REQUEST_SCOPE;
    String ref = null;
    String id = null;
    boolean debug = false;
    boolean display = false;
    StringBuffer body = null;
}



And the TEI class would be like this:

package com.mycompany.jsp.taglibs.Text;

import javax.servlet.jsp.tagext.*;

public class TextTEI
extends TagExtraInfo
{
    public VariableInfo[] getVariableInfo(TagData data)
    {
        String type = data.getAttributeString("type");
        String s = data.getAttributeString("id");
        boolean declare = true;
        
        if(s==null)
        {
            s = data.getAttributeString("ref");
            declare=false;
        }
        
        VariableInfo vinfo =
        new VariableInfo(
            s,
            type ==null?
            "StringBuffer":type,
            declare,
            VariableInfo.AT_END);
        VariableInfo[] info = {vinfo};
        return info;
    }
Comment 4 Mi Amidot CLA 2006-08-29 15:13:47 EDT
The above code is example of using tag body as attribute value.
Depending how tag class is written, a tag could be programmed to store almost anything as attribute value, not just the tag body. The spontaneous/automatic variable name presented to a JSP would be the getId() of the tag.
Comment 5 Mi Amidot CLA 2006-08-29 15:16:45 EDT
Does this mean you guys have never used struts tag lib?
Comment 7 Nitin Dahyabhai CLA 2006-09-06 14:21:49 EDT
(In reply to comment #2)
Michael, the actual error text would be more helpful than an image of content assist.  Was the error message for "a1" saying that it couldn't be resolved?  I also noticed that the end tag was not underlined in this case.
Comment 8 Nitin Dahyabhai CLA 2006-09-11 14:39:13 EDT

*** This bug has been marked as a duplicate of 87143 ***
Comment 9 Mi Amidot CLA 2006-11-01 12:48:04 EST
Thanks.

In response to
"Michael, the actual error text ... "

jfyi,
Mi does not stand for Michael.
Depending on certain charateristics, in hebrew "mi" could mean either
from (shortened from min)
who.

Amidot is a pluralisation of amidah which is from root word amod (to stand).
Amidah is also nickname for a series of liturgy made while standing.
Comment 10 Nitin Dahyabhai CLA 2006-11-01 13:23:57 EST
(In reply to comment #9)
> jfyi,
> Mi does not stand for Michael.

My mistake, but then without knowing whether MyEclipse 5 Pro includes WTP 1.5.1, there's no way to tell if this is really the same problm or something else (such as the library having been built with a newer class version than the IDE's JRE supports, missing dependencies for loading the class, etc.).  Can you find the version of the org.eclipse.jst.jsp.core plugin that's installed and running?
Comment 11 John Lanuti CLA 2006-11-28 15:51:02 EST
This is part of a mass update to close out all stale WTP bugs which are in the resolved state without an appropriate targeted version.  If you feel this bug was closed inappropriately, please reopen.