jsf 2方法参数操作侦听器 [英] jsf 2 method parameters action listener

查看:151
本文介绍了jsf 2方法参数操作侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将变量传递给方法参数:

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

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

出于某种原因,这似乎总是将0传递给方法.

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

推荐答案

仅当您使用

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

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

,您正在运行支持Servlet 3.0/EL 2.2的容器(Tomcat 7,Glassfish 3,JBoss 6等),并且已声明您的web.xml符合带有以下根声明的Servlet 3.0规范

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">

如果后两种情况不适用于您的情况(例如,您使用的是Servlet 2.5),则需要用另一种支持EL的实现(例如JBoss EL)替换EL实现.有关详细信息,请参见此答案.

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.

这篇关于jsf 2方法参数操作侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆