facebook

JSP validation does not take static includes into account

  1. MyEclipse Archived
  2.  > 
  3. Bugs
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #253809 Reply

    henk
    Member

    Eclipse 3.2rc6 / MyEclipse 5.0rc2 / Java5u6 / WinXP SP2

    I’ve been running MyEclipse validation on my project. It seems that the validator does not take static includes into account. Some pages have a static include that defines a method for the JSP page, but this is flagged as “The method foo(int) is undefined for the type __2F_example_project_2F_Web_20_Root_2F_test_2E.jsp”. This is a bogus error, since the method is there. The page runs flawless on Tomcat 5.5 (all versions).

    I know it’s bad practice to use static includes this way, but I would have suspected a “bad practice” warning instead of an “undefined” error.

    It’s not just method definitions. It’s also for imports that appear in static includes, which leads to “BarClass cannot be resolved to a type” and also for variables that are declared into an staticly included file which lead to “kazinstance cannot be resolved”.

    There files are all included with:

    <%@ include file=”/includes/xyz.jspf” %>

    #253822

    Riyad Kalla
    Member

    I don’t follow, how did you define a method in xyz.jspf? The validator does honor includes (like if you define variables or taglibs in your include, they are seen in the parent page), but methods? AFAIK that’s not valid… atleast I can’t think of how it’s valid, if you take a look at your generated Servlet from the JSP, your scriptlet code get’s inlined into the generated Servlet method body, so defining a method in an include would effectively inline a method in a method… =/

    #253843

    arjan.tijms
    Member

    Riyad, you can define methods in static jsp includes.

    If you make an include like this:

    
    <%! String somemethod() { return "bla"; } %>
    

    and then save this file to /includes/xyz.jspf, you can inline it in a JSP page with:

    
    <%@ include file="/includes/xyz.jspf" %> 
    

    You’ll see that a method has been added if you look at the generated servlet code for the JSP which used this include. Don’t forget that STATIC includes are inlined at compile time. Basically anything you can directly put into a JSP file can be put into such a ‘fragment’. Defining a function inside a JSP (note the exclamation mark in the escape sequence <%! ) is not a very good style, but nevertheless legal. Since its legal inside a JSP, its also legal inside a static include.

    More on topic, we’re currently testing the 5.0M1 release too and we have been seeing the same issues. It seems they only appear when you do a full scale manual validation (i.e. right clicking your project root and then selecting Run Validation from the MyEclipse menu). Everything a static include introduces to the including JSP’s scope is ignored by the validator. On top of that we weren’t able to ctrl-click on the name of the include in the include tag.

    Additionally, the validator doesn’t recognize the <jsp:attribute> tag inside custom tags. (message is: unknown tag).

    We’re having some custom tags that have an XML fragment as the body of the jsp:attribute tag. This entire body is validated by the validator which is of course not what it should do (for the validator it should just be a string).

    E.g.

    
    <tableflow:table
       tableflow.builder.mode="${tableCtrl.mode}"
    >
       <jsp:attribute name="tabledef" >
          <table builder_class="com.mbuyu.tableflow.plugins.std.ModeTableBuilder" />
          <!-- more custom non taglib XML below -->
       </jsp:attribute>
    </tableflow:table>
    

    In this case, there are yellow warning lines from jsp:attribute to /jsp:attribute.

    #253872

    Riyad Kalla
    Member

    Arjan,
    First let me thank you for the detailed information, I’m not sure if it’s good or bad I wasn’t aware of <%! up until now. More importantly, would you be able to put together a sample Web Project that exhibits all these problems and send it to me (support@genuitec.com ATTN Riyad) with descriptions of what should be happening, I can test and verify and send it to the dev team. We just closed out a handful of validation issues this morning and I would like these covered as well if possible in the 5.0 release or soon there after.

    #254031

    dionic
    Member

    Hi Riyad,

    I noticed some similarity to Arjan’s JSP validation of includes on my side. I’m running MyEclipse 5.0M1 with Eclipse 3.2rc7.
    I think I’ve pin-pointed the problem to absolute versus relative include file locations.
    I’ve found that validation works perfectly for relative includes but not for absolute includes, e.g. the following is a relative include

    
    <%@ include file="./shared/header.jsp"%>
    

    Notice the period/dot “.” before the /shared, thus making the link relative. If your header.jsp file contains any variable or method definitions… these will be available in the including file.

    However, if you make the link absolute, i.e. start with a slash “/”, (as I noticed in Arjan’s case and with ALL of our jsp’s unfortunately 😉 )… the validation DOESN’T work… and any references to variables and methods in the include file are NOT picked up in the including file.

    Here are some test files you can create to reproduce this problem:

    Filename: index.jsp (create this in the root of a new Web project)

    
    <%@ include file="./shared/header.jsp" %>
     
      <body>
        Hello <%=name%>!<br>
      </body>
      
    <%@ include file="./shared/footer.jsp" %>
    

    Now create the header and footer files in a “/shared” folder as follows:
    Filename: /shared/header.jsp

    
    <%!
      String name = "Bob"; 
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Header Title</title>
      </head>
    

    Filename: /shared/footer.jsp

    
    </html>
    

    If you copied the above identically, you will notice code completion works on the “name” variable in the index.jsp file, showing that the JSP validation works and picks up the code in the included files. And if you run this index.jsp file on an app server or servlet container you should get “Hello Bob!” as the output.

    Now… go and remove those periods before the /shared includes in the index.jsp file. This absolute reference still refers to the same files and if you save and test in a browser you will still see the “Hello Bob!” output (so the code is valid), however, this time the code completion on the “name” variable fails, because the JSP validitor cannot follow the absolute reference to the include files.

    This used to work on previous MyEclipse releases… as all of our apps have been developed in MyEclipse and have been validating perfectly until I installed 5.0M1. I really enjoy the speed of the JSP editor in 5.0M1 which is why I’m running on it (as you may recall from my previous posts)… and I’m slowly converting the rest of my team as well… although this current validation issue a problem. It’s fine if you trust your jsp skills and can turn all the validation off (as I have done)… but my other developers are complaining that they need it… so I’m holding thumbs. Note: even if you have a patch I can run independently I’d appreciate it otherwise we’ll just have to hold out till the next release. Unless you have an awesome config setting that solves my problem hidden away in the Preferences, although I doubt it because I have searched quite hard 😉

    I’m not sure if it’s good or bad I wasn’t aware of <%! up until now.

    Just a note on ! declarations… I’ve used the ! for the declaration of the “name” variable in the header.jsp file above. You can play with removing it and adding it. You will see that it’s syntactically correct to include it, however if you do remove it, everything still compiles and still runs. You will notice however that the JSP validator shows a warning that the local variable name is never read… so adding the ! allows the variable to exist outside its local scope (for the validator anyway).

    I hope this helps.

    Regards
    Charles

    #254179

    Thanks everyone, I added a problem report, we will try to fix it.

    #254266

    I was terribly wrong – ME did not support absolute paths in includes. You can revert to relative paths or wait a couple days for M2 that doesn’t have this problem.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: JSP validation does not take static includes into account

You must be logged in to post in the forum log in