从 JSF 1.2 页面访问 bean 方法 - 钩子生命周期?黑客攻击者?
我想做类似的事情(在 jsf 1.2 中):
<html>
...
#{myObject.foreignKey(parentObject.primaryKey)}
<h:inputText value="#{myObject.myProperty}"/>
</html>
或者换句话说:从网页中,我想在到达该页面时在对象中设置一个值。
虽然这在 JSF 2.0 中很容易,但在 JSF 1.2 中似乎有点不可能 有没有解决这个问题的黑客/解决方法? 定义一个以对象和字符串/整数作为参数的函数并处理返回的对象? 覆盖 inputText (和所有其他输入字段)并访问所有类型的框架相关类似乎很脏
I want to do something similar to this (in jsf 1.2):
<html>
...
#{myObject.foreignKey(parentObject.primaryKey)}
<h:inputText value="#{myObject.myProperty}"/>
</html>
Or in other words: from the web page I want to set a value in an object when arriving on that page.
while this is easy in JSF 2.0, it seems kinda impossible in JSF 1.2
Is there a hack / workaround for this?
Define a function which takes as argument an object and a String/integer and work on the returned object?
Overwriting inputText (and all other input fields) and accessing all kind of framework related classes seems dirty
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是特定于 JSF 实现,而是特定于 EL 实现。在 Java EE 6 的 EL 2.2 之前的标准 EL 实现中你不能像这样传递方法参数。除了升级到支持 EL 2.2 的 servlet 容器(Tomcat 7、Glassfish 3、JBoss 6 等)之外,您还可以自己替换 EL 实现。实现特定要求的常用方法是 JBoss-EL。下载并放置
jboss-el.jar
位于/WEB-INF/lib
中,并将以下内容添加到web.xml
,假设您使用 Mojarra 作为 JSF 实现:另一种方法是使用 JSTL
:请注意,
xmlns:c="java.sun.com/jstl/core"
上的 Facelets 内置 JSTL 库还包含 < code>c:set,但这在功能上受到很大限制。xmlns:c="java.sun.com/jsp/jstl/core"
需要一个完整的 JSTL 库,该库通常已经与成熟的 servlet 容器一起提供。然而,例如在 Apache Tomcat 中,您必须自己下载并安装它。有关链接和更多详细信息,请参阅我们的 JSTL wiki 页面。This is not specific to JSF implementation, but to the EL implementation. In standard EL implementation prior to EL 2.2 from Java EE 6 you cannot pass method arguments like that. Apart from upgrading to a servletcontainer which supports EL 2.2 (Tomcat 7, Glassfish 3, JBoss 6, etc), you can also replace the EL implementation yourself. A commonly used one to achieve the particular requirement is JBoss-EL. Download and put
jboss-el.jar
in/WEB-INF/lib
and add the following to theweb.xml
, assuming you're using Mojarra as JSF implementation:An alternative is just using JSTL
<c:set>
:Note that the Facelets' builtin JSTL libs on
xmlns:c="java.sun.com/jstl/core"
also contains ac:set
, but this is pretty restricted in functionality. Thexmlns:c="java.sun.com/jsp/jstl/core"
requires a fullworthy JSTL lib which is usually already shipped along with a bit fledged servletcontainer. However, in Apache Tomcat for example, you've got to download and install it yourself. For links and more detail, see our JSTL wiki page.