模板文本中不允许#{...} [英] #{...} is not allowed in template text

查看:999
本文介绍了模板文本中不允许#{...}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

在将JSP用作视图技术并且在模板文本中使用#{...}时,会出现此错误,例如(<p>是只是示例,它可以是任何纯HTML元素):

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>

JSP不支持它,但是其后续Facelets支持它.在JSP中,您需要显式使用<h:outputText>:

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>

但是,在您已经在JSF组件中使用#{...}的特定代码段中,只有在a4j标记库没有被<%@ taglib %>正确注册为JSP标记库时,才会发生这种情况,或者在类路径中找不到a4j标记库.这样,不会解析<a4j:ajax>标记,因此将其视为纯文本,包括带有EL表达式的所有属性.因此#{question.setParameters}在模板文本中被视为EL,JSP不支持.

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.

但是您的问题更大:<a4j:ajax>所属的RichFaces 4.x组件库不支持JSP .自JSF 2.0以来,已弃用JSP,Facelets继承了JSP.所有JSF组件库(例如RichFaces)都决定放弃对JSP的支持,因为开发和支持两种不同的视图技术JSP和Facelets的标记库和组件是一项艰巨的工作.因此,即使在类路径中已经有RichFaces 4.x,并且已经通过<%@ taglib %>正确注册了它,它也不会在JSP中工作,这仅仅是因为a4j命名空间不存在JSP .tld文件.

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.

为了使用与JSF 2.0兼容的组件库,您必须从JSP迁移到Facelets.一种替代方法是改用较旧的RichFaces 3.x版本.版本3.3.3在JSP上支持JSF 2.0.它提供了<a4j:support>标记以实现相同目的.但是请记住,您正在以这种方式落后于技术.您应该继续前进.删除JSP并使用其后续Facelets.

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.

  • Migrating from JSF 1.2 to JSF 2.0
  • Our Facelets wiki page - contains several tutorial links at the bottom

这篇关于模板文本中不允许#{...}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆