Bug 54012 - No "pageContext" in tag files' generated java code when using code generation by JSTL tagplugin "Set"
No "pageContext" in tag files' generated java code when using code generation...
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Jasper
trunk
PC All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-10-16 09:01 UTC by Sheldon Shao
Modified: 2012-10-25 12:04 UTC (History)
0 users



Attachments
Patch for org.apache.jasper.tagplugins.jstl.core.Set.java (1.56 KB, patch)
2012-10-16 09:01 UTC, Sheldon Shao
Details | Diff
Patch for Compiler.java (630 bytes, patch)
2012-10-16 09:02 UTC, Sheldon Shao
Details | Diff
Patch for PageInfo.java (970 bytes, patch)
2012-10-16 09:03 UTC, Sheldon Shao
Details | Diff
Patch for TagPluginContext.java (479 bytes, patch)
2012-10-16 09:03 UTC, Sheldon Shao
Details | Diff
Patch for TagPluginManager.java (951 bytes, patch)
2012-10-16 09:03 UTC, Sheldon Shao
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sheldon Shao 2012-10-16 09:01:56 UTC
Created attachment 29485 [details]
Patch for org.apache.jasper.tagplugins.jstl.core.Set.java

The code generated by the following code from " org.apache.jasper.tagplugins.jstl.core.Set" can't work in Tag Files.

There is no "PageContext" in tag file. So this should check "isTagFile".

            String strVar = ctxt.getConstantAttribute("var");
            ctxt.generateJavaSource("if(null != " + resultName + "){");
            ctxt.generateJavaSource("    pageContext.setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");");
            ctxt.generateJavaSource("} else {");
            if(hasScope){
                ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");");
            }else{
                ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\");");
            }
            ctxt.generateJavaSource("}");
Comment 1 Sheldon Shao 2012-10-16 09:02:18 UTC
Comment on attachment 29485 [details]
Patch for org.apache.jasper.tagplugins.jstl.core.Set.java

>Index: org/apache/jasper/tagplugins/jstl/core/Set.java
>===================================================================
>--- org/apache/jasper/tagplugins/jstl/core/Set.java	(revision 1370136)
>+++ org/apache/jasper/tagplugins/jstl/core/Set.java	(working copy)
>@@ -70,14 +70,20 @@
>         
>         //if the attribute var has been specified then assign the result to the var;
>         if(hasVar){
>+            String jspCtxt = null;
>+            if (ctxt.isTagFile()) {
>+                jspCtxt = "this.getJspContext()";
>+            } else {
>+                jspCtxt = "_jspx_page_context";
>+            }
>             String strVar = ctxt.getConstantAttribute("var");
>             ctxt.generateJavaSource("if(null != " + resultName + "){");
>-            ctxt.generateJavaSource("    pageContext.setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");");
>+            ctxt.generateJavaSource("    "+jspCtxt+".setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");");
>             ctxt.generateJavaSource("} else {");
>             if(hasScope){
>-                ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");");
>+                ctxt.generateJavaSource("    "+jspCtxt+".removeAttribute(\"" + strVar + "\"," + iScope + ");");
>             }else{
>-                ctxt.generateJavaSource("    pageContext.removeAttribute(\"" + strVar + "\");");
>+                ctxt.generateJavaSource("    "+jspCtxt+".removeAttribute(\"" + strVar + "\");");
>             }
>             ctxt.generateJavaSource("}");
>
Comment 2 Sheldon Shao 2012-10-16 09:02:40 UTC
Created attachment 29486 [details]
Patch for Compiler.java
Comment 3 Sheldon Shao 2012-10-16 09:03:03 UTC
Created attachment 29487 [details]
Patch for PageInfo.java
Comment 4 Sheldon Shao 2012-10-16 09:03:26 UTC
Created attachment 29488 [details]
Patch for TagPluginContext.java
Comment 5 Sheldon Shao 2012-10-16 09:03:47 UTC
Created attachment 29489 [details]
Patch for TagPluginManager.java
Comment 6 Mark Thomas 2012-10-25 12:04:31 UTC
Thanks for the patch. I applied a slightly modified version to trunk and 7.0.x. I also added a test case to trunk. The fix will be in 7.0.33 onwards.