Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#{...} is not allowed in template text

Tags:

jsf

ajax4jsf

<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?

like image 343
Sanat Pandey Avatar asked Sep 18 '12 14:09

Sanat Pandey


2 Answers

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.

See also:

  • Migrating from JSF 1.2 to JSF 2.0
  • Our Facelets wiki page - contains several tutorial links at the bottom
like image 80
BalusC Avatar answered Oct 16 '22 19:10

BalusC


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.

like image 32
user1512999 Avatar answered Oct 16 '22 21:10

user1512999