当为其他组件指定了流程属性时,PrimeFaces Ajax侦听器未执行 [英] PrimeFaces Ajax Listener not executed when process attribute is specified for a different component

查看:92
本文介绍了当为其他组件指定了流程属性时,PrimeFaces Ajax侦听器未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我指定p:ajax标签的process属性时,不执行侦听器.如果省略process属性,则会按预期方式调用侦听器.

When I specify process attribute of p:ajax tag, the listener is not executed. If I omit the process attribute, then the listener is called as expected.

这是视图片段:

<p:messages id="messages" />
<h:inputText id="inputToProcess" value="#{controller.inputToProcess}" />
<p:selectBooleanCheckbox id="testCheckbox" >
  <p:ajax event="change" process="inputToProcess"
    update="messages @this inputToUpdate"
    listener="#{controller.processChecked}" />
</p:selectBooleanCheckbox>
<h:inputText id="inputToUpdate" value="#{controller.inputToUpdate}" />

和控制器:

@javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
public class Controller implements Serializable {
  private String inputToProcess;
  private String inputToUpdate;
  //getters and setters

  public void processChecked(javax.faces.AjaxBehaviorEvent e) {
    // doing some stuff here
  }
}

我将phaseListener附加到具有ANY_PHASE PhaseId 的视图,这就是我观察到的.

I attached a phaseListener to a view with ANY_PHASE PhaseId, and here is what I observed.

当我指定process属性时,在更新模型阶段将 inputToProcess 输入的值成功设置为控制器(不会发生任何异常).然后,执行Invoke ApplicationRender Response阶段,但不调用任何侦听器.我注意到的一件事是最后没有设置复选框.但是,没有转换或验证错误,因为正如我所说的,Update ModelInvoke Application阶段已执行.

When I specify process attribute , the value of the inputToProcess input is successfully set to the controller during the Update Model phase (no exception occurs). Then the Invoke Application and Render Response phases are executed, but no listener is called. One thing I noticed is that checkbox is not set in the end. But, there are no conversion or validation errors, because as I said the Update Model and Invoke Application phases are executed.

如果我省略了process属性,这是我看到的结果:通常在Invoke Application阶段调用侦听器(因为默认情况下immediate为false),然后执行渲染响应".复选框已成功设置.

If I omit process attribute, here is what I see: the listener is normally called during the Invoke Application phase (since immediate is false by default), and then `Render Response is executed. Checkbox is successfully set.

对这种行为有解释吗?

推荐答案

一见钟情.至少,在使用标准JSF组件时,它可以很好地工作.我敢打赌这是PrimeFaces的错误或功能",即当process中未包含动作组件时,它不会处理动作.将@this添加到process应该可以解决该问题.考虑将问题报告发布给PrimeFaces员工.

It should work fine at first sight. At least, it works fine that way when using standard JSF components. I'd bet it to be a bug or "feature" of PrimeFaces that it doesn't process the action when the action component is not included in the process. Adding @this to process should solve it. Consider posting an issue report to PrimeFaces guys.

此外,我宁愿使用event="valueChange"event="click"而不是event="change"或仅完全删除event,它已经默认为正确的值(valueChange将在复选框中呈现onclick和单选按钮组件). change事件在MSIE中对于复选框和单选按钮的工作方式有所不同.仅在第二次点击时触发.您不想依赖于浏览器.

Further, I'd rather use event="valueChange" or event="click" instead of event="change" or just remove the event altogether, it defaults to the right value already (valueChange which will render onclick in checkbox and radio button components). The change event works differently in MSIE for checkboxes and radiobuttons. It's only triggered on 2nd click and forth. You don't want to be browser dependent.

根据您的评论:

标准JSF复选框和ajax组件的问题在于,在流程验证阶段调用了侦听器,但是我需要先更新模型!

这不是事实.可能是您使用的是valueChangeListener而不是<f:ajax listener>或使另一个混淆. <f:ajax listener>始终在调用操作阶段被调用.

This is not true. Probably you was using valueChangeListener instead of <f:ajax listener> or confusing the one with the other. The <f:ajax listener> is always invoked during invoke action phase.

这篇关于当为其他组件指定了流程属性时,PrimeFaces Ajax侦听器未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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