【问题标题】:How to pass a parameter to backing bean using EL expression in JSF component?如何使用 JSF 组件中的 EL 表达式将参数传递给支持 bean?
【发布时间】:2013-06-29 23:53:02
【问题描述】:

我有这个组件:

<t:outputText value="#{bean.name}">

我想在 EL 表达式中调用带参数的方法而不是调用 getter,但我没有 JSF 2.0。

如何使用 EL 将参数传递给支持 bean 中的方法 没有 JSF 2.0 的表达式?

换句话说,我想做这样的事情:

 <t:outputText value="#{bean.findName(#{bean.name})}">

外部表达式:在后台bean中调用带有参数的方法。

内部表达式:调用getter作为方法中的参数。

backing bean中的方法:

public String findName(String name){


}

先谢谢了! :)

【问题讨论】:

标签: jsf jsf-1.2


【解决方案1】:

方法参数是 EL 2.2 的一个特性,因此您需要下载适当的 JAR 并将它们添加到您的项目中。如果您使用的是 Maven,请转到此链接

https://uel.java.net/download.html

(或直接进入 Maven 中心)

然后在web.xml中添加以下内容

<context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>

编辑

这是您评论的后续内容。你可以做这样的事情。

<h:inputText value="#{bean.id}">  <---This one will set the id
<h:outputText value="#{bean.name}"> <--- This one will display the name

并像这样定义你的方法

private Integer id; //Make setter and getter
private String name; //Make setter and getter for this. 

private Integer setId(Integer id) { //Make a getter also
   name = findName(id); // <--- Set the name property there
}

public String findName(Integer id) { 

    return name found in db; 

}

这只是一个想法。

【讨论】:

猜你喜欢
  • 2011-06-09
  • 2012-02-01
  • 1970-01-01
  • 2012-12-25
  • 2014-06-14
  • 2011-07-24
  • 2012-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多