jsf 2 method parameters action listener

白昼怎懂夜的黑 提交于 2019-12-23 04:13:20

问题


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:


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.



来源:https://stackoverflow.com/questions/5970721/jsf-2-method-parameters-action-listener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!