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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

hhmm...just upgraded to jetty 8...changed the web-xml and still having the same issue..using glassfish el-impl.
I have this in my faces-config...<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>...Will that be a problem?
ahh.the problem was I was retrieving currentItem from the URL and when I submitted this was getting wiped..will raise a separate question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.