2013-07-02 90 views
1

我有这个组件:如何使用JSF组件中的EL表达式将参数传递给支持bean?

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

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

如何使用不带JSF 2.0的EL 表达式将参数传递给backing bean中的方法?

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

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

外表达:要拨打与在支持Bean的参数的方法。

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

在支持bean的方法:

public String findName(String name){ 


} 
提前

谢谢! :)

+0

[在EL中调用具有参数/变量/参数的直接方法或方法]的可能重复(http://stackoverflow.com/questions/3284236/invoke-direct-methods-or-methods-with-arguments-variables- parameters-in-jsf) – BalusC

+1

每个人似乎都看不到的重要说明:功能不是特定于JSF 2.0,而是特定于EL 2.2。 – BalusC

回答

0

方法参数是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; 

} 

这只是一个想法。

+0

使用旧的应用程序服务器时,可能还需要安装JBoss EL。请参阅http://stackoverflow.com/a/3284328/1713801。 – alterfox

+0

@alterfox很高兴知道谢谢。 – Andy

相关问题