DD.
DD.

Reputation: 22011

jsf 2 method parameters action listener

Is there a way to pass a variable into a method param:

 <h:commandButton value="Add to Order" 
 actionListener="#{orderBasket.addItems(currentItem.id)}"/>

This always seems to pass 0 into the method for some reason.

Upvotes: 1

Views: 4420

Answers (1)

BalusC
BalusC

Reputation: 1109645

That's only possible when you use action instead of actionListener

<h:commandButton value="Add to Order" 
    action="#{orderBasket.addItems(currentItem.id)}"/>

and you're running a Servlet 3.0 / EL 2.2 capable container (Tomcat 7, Glassfish 3, JBoss 6, etc) and your web.xml is declared conform Servlet 3.0 spec with the following root declaration

<web-app
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

If the latter two are not true for your case (e.g. you're using Servlet 2.5), then you need to replace the EL implementation by another one which supports that, such as JBoss EL. For detail, see this answer.

Upvotes: 2

Related Questions