1

I have this component:

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

I want to call a method with a parameter in the EL expression instead of calling a getter, but I don't have JSF 2.0.

How can I pass a parameter to a method in the backing bean using EL expression without JSF 2.0?

In other words, I want to do something like this:

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

Outer expression: To call a method with a parameter in the backing bean.

Inner expression: To call a getter to use as a parameter in the method.

The method in the backing bean:

public String findName(String name){


}

Thanks ahead! :)

karthikr
  • 97,368
  • 26
  • 197
  • 188
MightGod
  • 436
  • 2
  • 8
  • 19
  • possible duplicate of [Invoke direct methods or methods with arguments / variables / parameters in EL](http://stackoverflow.com/questions/3284236/invoke-direct-methods-or-methods-with-arguments-variables-parameters-in-jsf) – BalusC Jul 02 '13 at 16:19
  • 1
    Important note which everyone seems to fail to see: feature is not specific to JSF 2.0, but to EL 2.2. – BalusC Jul 02 '13 at 16:21

1 Answers1

0

Method parameters are a feature of EL 2.2 so you need to download the appropriate JARs and add them to your project. If you are using Maven go to this link

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

(or go straight to Maven central)

Then add the following in web.xml

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

EDIT

This is a follow up from your comment. You could do something like this.

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

and define your methods like this

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; 

}

This is just an idea.

Andy
  • 5,900
  • 2
  • 20
  • 29
  • When using older application servers, it may also be necessary to install JBoss EL. See http://stackoverflow.com/a/3284328/1713801. – alterfox Dec 06 '13 at 15:01