<p:blockUI> does not respond on <h:commandButton><f:ajax>

感情迁移 提交于 2019-12-11 04:12:36

问题


I got a <h:commandButton like:

<h:commandButton id="login"
  actionListener="#{bean.login}" value="Login"
  styleClass="btn btn-primary btn-sm">
   <f:ajax execute="@form" render="@form"/>
</h:commandButton>

and a

<p:blockUI id="block" block=":form" trigger="login" />

It is not working. The block is never shown up.

It does work with a <p:commandButton>.

How can I achieve it with a <h:commandbutton>. If that is not possible: Is there any workaround?


回答1:


The <p:blockUI> listens on PrimeFaces/jQuery-specific pfAjaxSend and pfAjaxComplete events only. Those events are triggered by all PrimeFaces ajax components, but not by standard JSF <f:ajax>.

You've 3 options:

  1. Replace <f:ajax> by <p:ajax> to let the <h:commandButton> send a PF/jQuery ajax request instead of a standard JSF one.

    <h:commandButton id="login" value="Login" action="#{bean.login}">
        <p:ajax process="@form" update="@form" />
    </h:commandButton>
    

    (note: carefully read Differences between action and actionListener)


  2. Attach a global listener on <f:ajax> which auto-triggers the PF/jQuery-specific events.

    jsf.ajax.addOnEvent(function(data) {
        if (data.status === "begin") {
            $(document).trigger("pfAjaxSend", [null, data]);
        }
        else if (data.status === "success") {
            $(document).trigger("pfAjaxComplete", [null, data]);
        }
    });
    

    Might have some undesired side-effects, though.


  3. Manually trigger a specific <p:blockUI> during <f:ajax> events.

    <f:ajax ... onevent="triggerBlockUI" />
    ...
    <p:blockUI widgetVar="widgetBlockUI" ... />
    

    With this JS function.

    function triggerBlockUI(data) {
        if (data.status === "begin") {
            PF("widgetBlockUI").show();
        }
        else if (data.status === "success") {
            PF("widgetBlockUI").hide();
        }
    }
    

Needless to say that option 1 is the most straightforward choice.




回答2:


Try p:commandlink Instead. I had the same problem for h:commandlink and its solved



来源:https://stackoverflow.com/questions/29683262/pblockui-does-not-respond-on-hcommandbuttonfajax

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