diff options
| author | Nick Sandonato | 2012-11-07 21:24:03 +0000 |
|---|---|---|
| committer | Nick Sandonato | 2012-11-07 21:24:03 +0000 |
| commit | 4305b41ed114390556aab681e545287b727d0a8b (patch) | |
| tree | 7b54aeb4b168fc401137a4580f1d119f614c937c | |
| parent | ca3d7061024bec20660e5f00d875b649917ca223 (diff) | |
| download | webtools.sourceediting-4305b41ed114390556aab681e545287b727d0a8b.tar.gz webtools.sourceediting-4305b41ed114390556aab681e545287b727d0a8b.tar.xz webtools.sourceediting-4305b41ed114390556aab681e545287b727d0a8b.zip | |
[376926] Wrong Validation Error Message -'pageContext cannot be resolved' for tag filev201211072124
3 files changed, 26 insertions, 14 deletions
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java index ae8de80918..c192067509 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/JSPTranslator.java @@ -147,9 +147,6 @@ public class JSPTranslator implements Externalizable { /** end line characters */ public static final String ENDL = "\n"; //$NON-NLS-1$ - /** session variable declaration */ - private static final String SESSION_VARIABLE_DECLARATION = "javax.servlet.http.HttpSession session = pageContext.getSession();" + ENDL; //$NON-NLS-1$ - /** footer text */ private static final String FOOTER = "}}"; //$NON-NLS-1$ @@ -171,7 +168,6 @@ public class JSPTranslator implements Externalizable { /** JSP tag name prefix */ static final String JSP_PREFIX = "jsp:"; //$NON-NLS-1$ - // these constants are to keep track of what type of code is currently being translated /** code in question is standard JSP */ protected final static int STANDARD_JSP = 0; @@ -205,6 +201,12 @@ public class JSPTranslator implements Externalizable { /** translated class service header */ String fServiceHeader = null; + /** The context of the translation */ + String fContext = null; + + /** The context's session */ + String fSession = null; + /** translated user defined imports */ private StringBuffer fUserImports = new StringBuffer(); @@ -708,8 +710,9 @@ public class JSPTranslator implements Externalizable { javaOffset += fServiceHeader.length(); // session participant if (fIsInASession) { - fResult.append(SESSION_VARIABLE_DECLARATION); - javaOffset += SESSION_VARIABLE_DECLARATION.length(); + final String sessionVariableDeclaration = "javax.servlet.http.HttpSession session = "+ fSession + ENDL; //$NON-NLS-1$ + fResult.append(sessionVariableDeclaration); + javaOffset += sessionVariableDeclaration.length(); } // error page if (fIsErrorPage) { @@ -1233,6 +1236,8 @@ public class JSPTranslator implements Externalizable { "javax.servlet.jsp.JspWriter out = pageContext.getOut();" + ENDL + //$NON-NLS-1$ "Object page = this;" + ENDL; //$NON-NLS-1$ fSuperclass = "javax.servlet.http.HttpServlet"; //$NON-NLS-1$ + fContext = "pageContext"; //$NON-NLS-1$ + fSession = fContext+".getSession();"; //$NON-NLS-1$ } /** @@ -2099,7 +2104,7 @@ public class JSPTranslator implements Externalizable { // 2.0:JSP.8.5.2 varType = "javax.servlet.jsp.tagext.JspFragment"; //$NON-NLS-1$ } - String declaration = new TaglibVariable(varType, varName, "", description).getDeclarationString(true, TaglibVariable.M_PRIVATE); //$NON-NLS-1$ + String declaration = new TaglibVariable(varType, varName, "", description).getDeclarationString(true, fContext, TaglibVariable.M_PRIVATE); //$NON-NLS-1$ appendToBuffer(declaration, fUserDeclarations, false, fCurrentNode); } } diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/TagTranslator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/TagTranslator.java index 2d7c17d021..f690171ca6 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/TagTranslator.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/TagTranslator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,11 +28,14 @@ class TagTranslator extends JSPTranslator { fServiceHeader = "public void doTag() throws JspException, java.io.IOException, IllegalStateException, SkipPageException {" + //$NON-NLS-1$ "javax.servlet.http.HttpServletResponse response = null;" + ENDL + //$NON-NLS-1$ "javax.servlet.http.HttpServletRequest request = null;" + ENDL + //$NON-NLS-1$ - "JspContext jspContext = null;" + ENDL + //$NON-NLS-1$ + "JspContext jspContext = getJspContext();" + ENDL + //$NON-NLS-1$ "javax.servlet.ServletContext application = null;" + ENDL + //$NON-NLS-1$ "javax.servlet.jsp.JspWriter out = null;" + ENDL + //$NON-NLS-1$ "javax.servlet.ServletConfig config = null;" + ENDL; //$NON-NLS-1$ fSuperclass = "javax.servlet.jsp.tagext.SimpleTagSupport"; //$NON-NLS-1$ + + fContext = "getJspContext()"; //$NON-NLS-1$ + fSession = "((PageContext)" + fContext + ").getSession();"; //$NON-NLS-1$ //$NON-NLS-2$ } } diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java index ab91ce9366..d6326d0646 100644 --- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java +++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/taglib/TaglibVariable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -108,6 +108,10 @@ public class TaglibVariable { * @return */ public final String getDeclarationString(boolean includeDoc, int style) { + return getDeclarationString(includeDoc, "pageContext", style); //$NON-NLS-1$ + } + + public final String getDeclarationString(boolean includeDoc, String context, int style) { String declaration = null; /* * no description for now --JDT would need to show it for local @@ -115,18 +119,18 @@ public class TaglibVariable { */ if (includeDoc && getDescription() != null) { if (style == M_PRIVATE) { - declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") "+context+".getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ } else { - declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ + declaration = "/** " + ENDL + StringUtils.replace(getDescription(), "*/", "*\\/") + ENDL + " */ " + ENDL + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") "+context+".getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ } } else { if (style == M_PRIVATE) { - declaration = "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + declaration = "private " + getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") "+context+".getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ } else { - declaration = getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") pageContext.getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + declaration = getVarClass() + " " + getVarName() + " = (" + getVarClass() + ") "+context+".getAttribute(\"" + getVarName() + "\");" + ENDL; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ } } return declaration; |
