在web.xml中使用JSF EL表达式 [英] using JSF EL expression inside web.xml

查看:344
本文介绍了在web.xml中使用JSF EL表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在web.xml中使用EL表达式吗?
喜欢这个

Can I use EL expression inside web.xml ? Like this

Web.xml

<context-param>
        <param-name>primefaces.DIR</param-name>
        <param-value>#{userUtilityBacking.direction}</param-value>
</context-param>

和我这样的JSF bean

and my JSF bean like this

JSF bean

@ManagedBean(name="userUtilityBacking")
@SessionScoped
public class UserUtilityBacking  implements Serializable {

     private static final long serialVersionUID = 1L;
    private String direction  ;   
// and public setters and getter 

它会起作用吗?

推荐答案


我可以在web.xml中使用EL表达式吗?

不完全是这样。默认情况下,在应用程序启动期间解析 web.xml 时,servletcontainer不会EL-评估上下文参数。但是,像Ant和Maven这样的构建工具和一些像JBoss这样的servlet容器(在设置特定的配置设置之后)支持使用类似于EL的内联环境变量的 $ {...} 语法和/或VM名称在几个部署描述符XML文件中的名称,例如 web.xml ejb-jar.xml persistence.xml 。注意:因此那些在JSF EL范围内声明的变量,例如托管bean。

Not exactly that. By default, the servletcontainer doesn't EL-evaluate the context parameters when the web.xml is been parsed during application startup. However, build tools like Ant and Maven and some servletcontainers like JBoss (after setting a specific configuration setting) support using ${...} syntax similar to EL to inline environment variables and/or VM arguments by their name in several deployment descriptor XML files such as web.xml, ejb-jar.xml and persistence.xml. Note: that are thus not those variables which you've declared in JSF EL scope, such as managed bean.


它会起作用吗?

它只会如果PrimeFaces获取静态值#{userUtilityBacking.direction}作为 String ,然后以编程方式EL评估它在当前的EL上下文中使用例如 Application#evaluateExpressionGet() 。但是,基于 PrimeFaces 3.5源代码,它在任何地方都没有这样做。看起来他们只为4.x实现了它。

It will only work if PrimeFaces gets the static value "#{userUtilityBacking.direction}" as String and then programmatically EL-evaluates it in the current EL context using for example Application#evaluateExpressionGet(). But, based on the PrimeFaces 3.5 source code, it is not doing that anywhere. It look like they implemented it for 4.x only.

在您的特定情况下,您最好直接在上指定方向< html> 元素,用于在文档范围内和/或在任意HTML或JSF组件的 dir 属性中应用它。

In your particular case, you'd better just specify the direction directly on <html> element to apply it document-wide and/or in dir attribute of an arbitrary HTML or JSF component.

<html dir="#{userUtilityBacking.direction}">

这篇关于在web.xml中使用JSF EL表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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