<a4j:ajax event="click" render="tempval" listener="#{question.setParameters}" />
When we are using this code, the server throws an exception with the message
#{...} is not allowed in template text
How is this caused and how can I solve it?
<a4j:ajax event="click" render="tempval" listener="#{question.setParameters}" />
When we are using this code, the server throws an exception with the message
#{...} is not allowed in template text
How is this caused and how can I solve it?
You will get this error when you're using JSP as view technology and you're using #{...}
in template text such as (the <p>
is just examplary, it can be any plain HTML element):
<p>#{bean.property}</p>
It's namely not supported in JSP, but it is supported in its successor Facelets. In JSP, you would need to explicitly use <h:outputText>
:
<p><h:outputText value="#{bean.property}"></p>
However, in your particular code snippet wherein you're using #{...}
in a JSF component already, that can only happen if the a4j
tag library is not properly been registered as a JSP tag library by <%@ taglib %>
, or if the a4j
tag library cannot be found in the classpath. This way the <a4j:ajax>
tag is not parsed and thus treated as plain text, including all attributes with EL expressions. So the #{question.setParameters}
is treated as EL in template text, which is not supported in JSP.
But your problem is bigger: the RichFaces 4.x component library, which the <a4j:ajax>
is part of, does not support JSP. JSP is deprecated since JSF 2.0 and succeeded by Facelets. All JSF component libraries such as RichFaces have decided to drop support for JSP, because it's a hell of a lot of work to develop and support tag libraries and components for the two different view technologies JSP and Facelets. So even if you have RichFaces 4.x already in the classpath and you've properly registered it by <%@ taglib %>
, it would never work in JSP, simply because the JSP .tld
file does not exist for the a4j
namespace.
In order to use JSF 2.0 compatible component libraries, you've to migrate from JSP to Facelets. An alternative is to use the older RichFaces 3.x version instead. Version 3.3.3 supports JSF 2.0 on JSP. It offers the <a4j:support>
tag to achieve the same. But keep in mind that you're going backwards in technology this way. You should keep moving forwards. Drop JSP and go for its successor Facelets.
I faced the same problem, for me the cause of the error was a commented line in javascript that use #{...} to assign value to a field in my page. once I removed it worked fine, sounds weird but this is what happened.
if you are using jsp as a view technology you need to import the below two libraries.
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
if you using xhtml add the below in html tag like
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core">
...
</html>