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

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

问题描述

<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 作为视图技术并且你在使用 #{...}模板文本,例如(

只是示例,它可以是任何纯 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 中,您需要显式使用 :

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>

但是,在您已经在 J​​SF 组件中使用 #{...} 的特定代码片段中,只有在 a4j 标记库中才会发生这种情况<%@ taglib %> 未正确注册为 JSP 标记库,或者如果在类路径中找不到 a4j 标记库.这样 标签不会被解析,因此被视为纯文本,包括所有带有 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.

但您的问题更大: 所属的 RichFaces 4.x 组件库不支持 JSP.JSP 自 JSF 2.0 起就被弃用,而由 Facelets 取而代之.所有 JSF 组件库(例如 RichFaces)都决定放弃对 JSP 的支持,因为为两种不同的视图技术 JSP 和 Facelets 开发和支持标记库和组件是一项艰巨的工作.因此,即使您的类路径中已经有 RichFaces 4.x 并且您已经通过 <%@ taglib %> 正确注册了它,它也永远不会在 JSP 中工作,仅仅因为 JSP a4j 命名空间不存在 >.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.它提供了 标签来实现相同的目的.但请记住,您正在以这种方式在技术上倒退.你应该继续前进.放弃 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天全站免登陆