Bug 123749 - JSP validation doesn't see variables in nested fragments
Summary: JSP validation doesn't see variables in nested fragments
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: jst.jsp (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows 2000
: P3 major with 4 votes (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Nitin Dahyabhai CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 157465 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-13 07:31 EST by Peik Aschan CLA
Modified: 2012-10-02 07:59 EDT (History)
4 users (show)

See Also:


Attachments
Picture showing the oddly placed error message (6.80 KB, image/png)
2006-01-13 07:34 EST, Peik Aschan CLA
no flags Details
Test JSP for reproducing the problem (379 bytes, text/plain)
2006-01-13 07:35 EST, Peik Aschan CLA
no flags Details
Test JSP for reproducing the problem: fragment 1 (106 bytes, text/plain)
2006-01-13 07:36 EST, Peik Aschan CLA
no flags Details
Test JSP for reproducing the problem: fragment 2 (104 bytes, text/plain)
2006-01-13 07:36 EST, Peik Aschan CLA
no flags Details
Example with nested JSP fragments bug. (604 bytes, application/gzip)
2011-08-26 12:13 EDT, Guram Z. Savinov CLA
no flags Details
Full example with nested JSP inclusion bug. (3.83 KB, application/gzip)
2011-08-26 18:03 EDT, Guram Z. Savinov CLA
no flags Details
Simple test case showing fragment that can't access main page variables (6.26 KB, application/octet-stream)
2012-10-02 05:46 EDT, phil wing CLA
no flags Details
Second test case showing fragments can't see imports from the main page (6.33 KB, application/octet-stream)
2012-10-02 05:53 EDT, phil wing CLA
no flags Details
Screenshot showing errors appearing in the wrong editor (48.02 KB, image/png)
2012-10-02 07:59 EDT, phil wing CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peik Aschan CLA 2006-01-13 07:31:49 EST
I have a JSP page which includes a fragment, which in turn includes another fragment: <main page <inlude fragment1 <include fragment2> > >

Fragment 1 declares a variable which is referenced in both fragment 1 and the main page. The variable is not seen by the JSP validator in the included fragment 2. This turns up as an oddly placed squiggly underlined error on the main JSP page (oddly placed since the supposed "error" is really in fragment 2).

I expected bug 87351 to fix this, but apparently this is a separate problem. Enabling or disabling "Validate JSP fragments" has no effect.

Example attached.
Comment 1 Peik Aschan CLA 2006-01-13 07:34:04 EST
Created attachment 32975 [details]
Picture showing the oddly placed error message
Comment 2 Peik Aschan CLA 2006-01-13 07:35:13 EST
Created attachment 32976 [details]
Test JSP for reproducing the problem
Comment 3 Peik Aschan CLA 2006-01-13 07:36:11 EST
Created attachment 32977 [details]
Test JSP for reproducing the problem: fragment 1
Comment 4 Peik Aschan CLA 2006-01-13 07:36:40 EST
Created attachment 32978 [details]
Test JSP for reproducing the problem: fragment 2
Comment 5 David Williams CLA 2006-03-28 03:24:24 EST
Mass transfer from pa to dw. Needs more triage. 
Comment 6 Naci Dai CLA 2006-12-11 04:19:46 EST
There is another example generating this bug:

http://forge.objectweb.org/tracker/index.php?func=detail&aid=305192&group_id=97&atid=100097
Comment 7 Aleksander Blomskøld CLA 2007-03-19 07:53:32 EDT
I think this might be related to a similar bug I'm having where you don't get get content assists for tag libs defined in an includes include, for instance:

taglibs.jspf:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

header.jspf (here I got content-assist for the <c:*>-tags):
<%@ include file="/WEB-INF/jsp/includes/taglibs.jspf" %>
<html>
(...)


main.jspf (here I dont have content-assist for the <c:*>-tags):
<%@ include file="/WEB-INF/jsp/includes/header.jspf" %>
(...)

Or should this be filed as a separate issue?
Comment 8 Nitin Dahyabhai CLA 2007-04-11 15:46:26 EDT
I suspect this was fixed as part of bug 174042.  Timely confirmation (or disagreement) by the reporter or a voter would be most appreciated.
Comment 9 Patric Rufflar CLA 2007-08-16 17:52:50 EDT
Sorry, but I can still see this bug in WTP 2.0 using the official Europa Build.

Just create a new project, create two jsp files. In on of them define a String variable and include (static include, using the include directive) the second jsp file. 

WTP reports within the second file that it cannot resolve the variable.
Just have a look at the example which have been attached by Peik Aschan.

The same applies to taglib declarations which aren't recognized in jsp fragments too.

It prevents validating all jsp fragments which we are using quite often in our company. This bug cause that almost every seconds line will be marked red which makes us impossible to get something out of the validation of jsp fragments.

The autocompletion of variables/taglibs which have been declared by parent jsp files is unavailable too, of course.

This is a very annoying, serious bug and I am waiting for almost two years for a fix.

It would be nice if somebody will raise the severity for this bug at least to major, but to be honest, for me it's a critical.

Best Regards,
Patric Rufflar

PS:
Bug 157465 which has been opened by me a year ago is a duplicate to this one. Sorry.
Comment 10 Patric Rufflar CLA 2007-08-16 17:54:17 EDT
*** Bug 157465 has been marked as a duplicate of this bug. ***
Comment 11 Nitin Dahyabhai CLA 2007-08-20 17:40:42 EDT
The current fix in place works for what the summary reads like, to me, that validation of JSP files doesn't take into account variables in nested fragments.  The original problem was the reverse, that validation of JSP fragment files can't see anything declared by the containing JSP file.  We're a bit stuck on this issue since there's no solution for determining which JSP file to treat as the parent of the fragment--typically there's more than one.
Comment 12 Patric Rufflar CLA 2007-08-23 10:10:00 EDT
Of course, a fragment may have more than one parent.
In my opinion the answer how to determine the "right" parent is easy:

Just every possible parent (which includes the fragment) has to be treated as a parent and there should be no compilation problems in any of the cases.
So as far I can see the best solution is that the validation process branches for each possible parent. If compilation errors occur, the error marker should contain the information in which case (parent) the compilation fails.


And Nitin, BTW: 
IMHO the original reporter did not describe the reverse case.
He wrote:
"Fragment 1 declares a variable which is referenced in both fragment 1 and the
main page. The variable is not seen by the JSP validator in the included
fragment 2."
So the inner fragment does not see variables from the outer one. And this is exact the case I described in my previous comment.
Comment 13 Peik Aschan CLA 2007-08-24 02:15:45 EDT
Thanks Patric for your comments. This bug is still relevant, and is an obvious bug (as you have correctly commented), and not a design problem of finding fragment parents. The error occurs in the parent JSP file (not in the fragment), as can be seen in the attached picture. So there is no need to determine the parent of a fragment in the context of this particular bug.

Nitin, there is  a separate bug 155664 to describe the problem you describe (the validation of fragment files in general, including the problem of finding the parents).

Patric, please add your suggested solution from comment #12 to bug 155664.
Comment 14 Patric Rufflar CLA 2007-08-27 08:38:52 EDT
Ok, I have to admit that this bug report confused me a little bit, because Peiks initial comment covers two different problems (which are connected, however):

Problem #1: a fragment cannot see declarations from its parent.
Problem #2: a parent cannot see declarations from an included fragment.

To follow Nitins and Peiks advice, I will treat this bug report only for problem #2 and bug 155664 for problem #1 (in which I reposted my comment #12).


Comment 15 Nitin Dahyabhai CLA 2009-04-20 00:07:30 EDT
Believed fixed in 3.1m7.  Unit test added.
Comment 16 Guram Z. Savinov CLA 2011-08-26 12:04:42 EDT
Problem with nested JSP fragments is not fixed in Eclipse 3.7 Indigo.
org.eclipse.jst.jsp.core, version v201105162116

Is it some patch or solutions?
Comment 17 Guram Z. Savinov CLA 2011-08-26 12:13:24 EDT
Created attachment 202245 [details]
Example with nested JSP fragments bug.

This is example with nested JSP fragments bug.
includes.jspf contain some spring tag libraries declarations.
header.jspf include includes.jspf
page.jspf include header.jspf and footer.jspf
Problem: eclipse don't see spring declarations from includes.jspf, therefore no autocomplete available and warnings about spring tags appears.

Files must be in /WEB-INF/views.

I finding solution or patch for this bug.
Can anybody help?
Comment 18 Nitin Dahyabhai CLA 2011-08-26 14:58:06 EDT
(In reply to comment #17)
> Created attachment 202245 [details]
> Example with nested JSP fragments bug.
> 
> This is example with nested JSP fragments bug.
> includes.jspf contain some spring tag libraries declarations.
> header.jspf include includes.jspf
> page.jspf include header.jspf and footer.jspf
> Problem: eclipse don't see spring declarations from includes.jspf, therefore no
> autocomplete available and warnings about spring tags appears.

Are you seeing error messages about the libraries not being found?

> Files must be in /WEB-INF/views.

Can you attach a complete example project including those libraries?  From what I can tell, content assist is fine in both page.jsp and header.jspf.
Comment 19 Guram Z. Savinov CLA 2011-08-26 18:03:55 EDT
Created attachment 202256 [details]
Full example with nested JSP inclusion bug.

This is full example with nested JSP inclusion bug. It is maven project. To build war just run: mvn package. You have target/abc.war, just deploy it in tomcat and try. Sources in src.
Interesting stuff in src/main/webapp/WEB-INF/views: includes.jspf, header.jspf and home.jsp. Bug is similar as previous: no autocompletion for <c:out ... /> tags and warnings about "unknown" <c:out ... /> tags.

Try it.
Comment 20 Nitin Dahyabhai CLA 2011-08-29 06:57:17 EDT
(In reply to comment #19)
> This is full example with nested JSP inclusion bug. It is maven project. To

Do you not have plug-ins supporting the use of Maven projects as WTP Dynamic Web Projects?  The attachment is missing all Eclipse project metadata, .project, .classpath,  and the .settings folder, as well as the tag libraries.

Are you seeing error messages in the Problems View about the libraries not being found?
Comment 21 Guram Z. Savinov CLA 2011-08-29 16:06:51 EDT
(In reply to comment #20)
> Do you not have plug-ins supporting the use of Maven projects as WTP Dynamic
> Web Projects?  The attachment is missing all Eclipse project metadata,
> .project, .classpath,  and the .settings folder, as well as the tag libraries.
> 
> Are you seeing error messages in the Problems View about the libraries not
> being found?

It's maven project, you don't need .classpath .setting and eclipse specific project files.

You can import it as maven project in eclipse or you can execute: 'mvn eclipse:eclipse' to generate all eclipse project files.

Because it's maven project, all dependencies, with taglibs will download by maven, not manually.
Comment 22 Nitin Dahyabhai CLA 2011-08-29 17:06:45 EDT
(In reply to comment #21)
> (In reply to comment #20)
> > Do you not have plug-ins supporting the use of Maven projects as WTP Dynamic
> > Web Projects?  The attachment is missing all Eclipse project metadata,
> > .project, .classpath,  and the .settings folder, as well as the tag libraries.
> > 
> > Are you seeing error messages in the Problems View about the libraries not
> > being found?
> 
> It's maven project, you don't need .classpath .setting and eclipse specific
> project files.
> 
> You can import it as maven project in eclipse or you can execute: 'mvn
> eclipse:eclipse' to generate all eclipse project files.
> 
> Because it's maven project, all dependencies, with taglibs will download by
> maven, not manually.

At development time we rely on those resources, and only support situations in which they exist.  Which makes it all the more surprising that you haven't confirmed that the Problems view and editor are reporting that those tag libraries were not being found.
Comment 23 phil wing CLA 2012-10-02 05:42:49 EDT
I'd like to request reopening of this bug.

I have a test project, with a file Test.jsp including a file Test.jspf.

Test.jsp defines a variable helloMain, and Test.jspf defines a variable helloFragment. Each tries to later reference the variable defined by the other.

With fragment validation switched on, Test.jsp shows no errors, however Test.jspf can't see helloMain. (an error is shown in the editor and problems view).

I could switch fragment validation off, but then I would lose some assistance. If there are actual valid errors in Test.jspf, I get errors shown in Test.jsp at the include directive, which is actually useful.

I'll attach my test project.

I also have a seperate bug - if a fragment has jsp scriptlets within a <script> tag (i.e. I'm trying to generate javascript dynamically) variables defined by the fragment can't be seen by the main page. Maybe I should raise that one seperately?
Comment 24 phil wing CLA 2012-10-02 05:43:43 EDT
I'm using the latest Juno 4.2 SR1 for EE developers, on winXP.
Comment 25 phil wing CLA 2012-10-02 05:46:00 EDT
Created attachment 221759 [details]
Simple test case showing fragment that can't access main page variables
Comment 26 phil wing CLA 2012-10-02 05:53:20 EDT
Created attachment 221760 [details]
Second test case showing fragments can't see imports from the main page

I've expanded the case to show that the fragment can't see java imports from the main page either.
Comment 27 phil wing CLA 2012-10-02 07:59:39 EDT
Created attachment 221771 [details]
Screenshot showing errors appearing in the wrong editor

I'm also getting the issue that if you have both files open, the errors from the jspf file show up randomly placed in the jsp file (as shown). There may already be a bug for this, maybe bug #153663.