我们正在从jsf 1.2升级到jsf 2。我们使用apache myfaces 2.1和rich faces 4.3。
下面是xhtml代码:
迁移前:
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:support event="onclick" ajaxSingle="true" actionListener="#{bean.processInput}" reRender="compId">
<f:param name="name" value="paramValue"/>
</a4j:support>
</h:selectBooleanCheckbox>我们通过传递一个参数,并接受actionListener方法中的参数:(String)context.getExternalContext().getRequestParameterMap().get("name1");
迁移后:
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:ajax event="click" listener="#{bean.processInput}" execute="@this" render="compId"/>
</h:selectBooleanCheckbox>我想要向bean.processInput方法传递一个参数,该方法具有以下签名:
public void processInput(AjaxBehaviorEvent event){根据这篇Issues in passing parameter in f:ajax后的文章,我们不能使用<f:param> (它也不能工作),我们也没有使用EL 2.2,它排除了在方法签名中传递参数。
由于xhtml页面中的约束,我们不能使用context.getApplication().evaluateExpressionGet,唯一可用的选项是使用<a4j:param name="" value="" assignTo=""/>.,但这需要在需要更改代码的bean中定义一个变量。
所以我的问题是,在第二种情况下,我们是否可以在不更改代码的情况下将参数从UI传递给listener。
发布于 2014-01-02 23:50:05
您可以像这样使用f:attribute:
<h:selectBooleanCheckbox id="comp1" value="#{bean.select}">
<a4j:ajax event="click" listener="#{bean.processInput}" execute="@this" render="compId"/>
<f:attribute name="name" value="paramValue" />
</h:selectBooleanCheckbox>并在您的bean中使用它:
public void processInput(AjaxBehaviorEvent event)
{
System.out.println(event.getComponent().getAttributes().get("name"));
}发布于 2014-10-14 09:24:54
确保f:attribute组件不是a4j:ajax的子组件。它应该是h:selectBooleanCheckBox的直接子组件,如果不是,则侦听器不会触发。
https://stackoverflow.com/questions/20886185
复制相似问题