Search code examples
jsfelmyfaces

How to include parameters inside a getter in JSF?


I was wondering if it was possible to pass parameters without using action/actionListener.

Here is an example:

<h:outputText value="#{myBean.getItem(5)}"/>
public String getItem(int index) {
     return itemList[index];
}

If the following does not work, is there another way to achieve the same result?


Solution

  • Since you are using myfaces on Tomcat 7 which already ships with EL 2.2 ,

    Make sure you have added below in web.xml and web.xml has version="3.0",

    <context-param>
        <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>
    

    Also make sure there are no el-api or el-imp jars in your WEB-INF/lib