[376926] Wrong Validation Error Message -'pageContext cannot be resolved' for tag file
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 ae8de80..c192067 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 @@
/** 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 @@
/** 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 @@
/** 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 @@
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 @@
"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 @@
// 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 2d7c17d..f690171 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 @@
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 ab91ce9..d6326d0 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 @@
* @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 @@
*/
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;