Some JSF taglibs such as Ajax4JSF mark the jsp-version tag in the TLD like this: <jsp-version>1.2</jsp-version> Then if a developer says something like action="#{foo}" in an Ajax4JSF tag, he will get this: This causes Ajax4JSF to fail with this error: org.apache.jasper.JasperException: /index.jsp(26,4) According to TLD or attribute directive in tag file, attribute action does not accept any expressions org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:406) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:147) Jasper tries to check the <jsp-version> in the TLD to see if the version is 2.1 and the attribute is not allowing deferred expressions. However, pre-2.1, "#{" had no meaning and was always allowed. In Validator.java, Jasper has this line: boolean checkDeferred = !tagInfo.getTagLibrary().getRequiredVersion().equals("2.0"); The problem is that while the logic will work if the TLD says <jsp-version>2.0</jsp-version>, it won't work for any jsp-version below that. A better way would be to say something like: float taglibRequiredVersion = Float.parseFloat(tagInfo.getTagLibrary().getRequiredVersion()); boolean checkDeferred = taglibRequiredVersion > 2.0f; I tried this and it works. However, this is not a complete fix because it doesn't catch NumberFormatException. Also, some refactoring might be in order because this same logic is found elsewhere in Validator.java and also in TagFileDirectiveVisitor. I'm not sure if the logic in those two places is correct or not. I'm attaching a war with a simple tag that demonstrates the problem. Stan
Created attachment 19215 [details] war for testing
I am not totally convinced this is really a bug. Maybe. Elsewhere in the class, there's a check for 1.2 and 2.0, which seems more accurate (and easier).
You could also say: boolean checkDeferred = (!version.equals("1.2") && !version.equals("2.0")) That takes advantage of the fact that 1.2,2.0, and 2.1 are the only versions where the <jsp-version> tag was defined. However, doing it that way doesn't allow someone to say <jsp-version>1.1</jsp-version>. Maybe it shouldn't be allowed so you throw an error in that case? As for it being a bug, I'm quite certain. An application written for JSP 1.2 should run the same in JSP 2.1. As of now, that is not true for taglibs with <jsp-version>1.2</jsp-version>. Backward compatibility is broken if an attribute value starts with "#{". Just try the WAR in Tomcat 5.5 and you will see that it works.
BTW, I suspect that this code in Validator.java is wrong as well (and I don't mean just the JSP 2.2 comment (-: ) // JSP.2.2 - '#{' not allowed in template text if (n.getType() == '#') { if (!pageInfo.isDeferredSyntaxAllowedAsLiteral() && (tagInfo == null || ((tagInfo != null) && !tagInfo.getTagLibrary().getRequiredVersion().equals("2.0")))) { err.jspError(n, "jsp.error.el.template.deferred"); } else { return; } }
I don't really see what these old tags should do with new pages and EL. Maybe it's supposed to remain compatible, but it does not make that much sense to me. It's fixed now.
FYI The old JSF tags processed the EL themselves. That's the root of the problem. So for an Ajax4JSF tag might look like this: <a4j:commandButton actionListener="#{mybean.action}"/> The tag would delegate to JSF 1.1 for processing the EL. This component still works in JSF 1.2 but now JSF 1.2 delegates back to the EL impl included in JSP 2.1. So, the old JSF tags need #{mybean.action} to be passed in as a simple String instead of a MethodExpression or ValueExpression object.