Menu

#338 TaglibFactory doesn't locate tld files properly

closed-fixed
5
2011-05-17
2011-01-04
No

I have a tld file in a jar file which is put inside WEB-INF/lib folder of my web application. It has the uri: "/test-tags". So when I do t=JspTaglibs["/test-tags"] in my ftl file, I get an error saying /test-tags cannot be found in location /test-tags.
It seems that TaglibFactory is trying to load the tld files before fetching locations from web.xml and libjar files. Because of this, getTldPath() method is called with empty locations map and it returns the actual URI in the path.

The possible solution can be to remove the do while loop in the get() method and put this

----------------------------------------------------------
getLocationsFromWebXml();
getLocationsFromLibJars();

if (taglib.load(uri, ctx, locations)) {
taglibs.put(uri, taglib);
return taglib;
}
----------------------------------------------------------

This ensures that all the locations are fetched before trying to load the tld based on the uri. I tested this code in my application and it works perfectly well.

Thanks
Satish

Discussion

  • Attila Szegedi

    Attila Szegedi - 2011-05-09

    Okay, I had an incorrect assumption in my code. I made an optimization so that it does not look up mappings in web.xml and JAR files if it can find the file denoted by an absolute (but local) URL. That speeds things up on startup, as TaglibFactory needn't scan all of the WEB-INF directory for .jar and .tld files necessarily, but you have proven it breaks if you want to map an absolute local URL in a .tld file.

    I have now made it to be similar to your fix - the lookups are now completely performed before the first taglib load attempt (but not earlier, so that if FreeMarker pages never use taglibs, we avoid scanning the WEB-INF for them)

    Interestingly, I also realized that we never had the functionality for scanning for .tld files within WEB-INF directory tree, only for .tld files in .jar files in /WEB-INF/lib, so we were in violation of the spec there too.

    I'll be fixing both issues.

     
  • Attila Szegedi

    Attila Szegedi - 2011-05-09
    • assigned_to: nobody --> szegedia
    • status: open --> open-accepted
     
  • Dániel Dékány

    Fixed in 2.3.17.

     
  • Dániel Dékány

    • status: open-accepted --> closed-fixed
     

Log in to post a comment.