| Summary: | JSP Editor does not recognise custom tag library | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [WebTools] WTP Source Editing | Reporter: | Mi Amidot <miamidot> | ||||
| Component: | jst.jsp | Assignee: | Nitin Dahyabhai <thatnitind> | ||||
| Status: | CLOSED DUPLICATE | QA Contact: | David Williams <david_williams> | ||||
| Severity: | major | ||||||
| Priority: | P3 | ||||||
| Version: | 1.5 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Mi Amidot
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? Created attachment 48991 [details]
Squiggy underline
Notice the squiggy underline? Implying that JSP editor does not parse the TLD of custom tags.
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; } 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. Does this mean you guys have never used struts tag lib? http://www.onjava.com/pub/a/onjava/2000/12/15/jsp_custom_tags.html http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html http://java.sun.com/developer/technicalArticles/xml/WebAppDev3/ http://java.sun.com/developer/Books/javaserverpages/cservletsjsp/chapter14.pdf (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. *** This bug has been marked as a duplicate of 87143 *** 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. (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? 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. |