1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

2

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • hhmm...just upgraded to jetty 8...changed the web-xml and still having the same issue..using glassfish el-impl. – DD. May 11 '11 at 22:32
  • I have this in my faces-config...org.springframework.web.jsf.el.SpringBeanFacesELResolver...Will that be a problem? – DD. May 11 '11 at 22:44
  • ahh.the problem was I was retrieving currentItem from the URL and when I submitted this was getting wiped..will raise a separate question – DD. May 12 '11 at 00:21