如何从Primefaces中的javascript触发组件刷新? [英] How to trigger component refresh from javascript in primefaces?

查看:247
本文介绍了如何从Primefaces中的javascript触发组件刷新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从javascript更新PrimeFaces组件,以便强制刷新?

Is it possible to update a PrimeFaces component from javascript so that it would be force to refresh?

我正在使用对话框中的此按钮进行ajax保存呼叫. 我已经在oncomplete事件上附加了自定义javascript.

I am making an ajax save call using this button in a dialog. I have attached my custom javascript on the oncomplete event.

<p:growl life="1500" id="showmessage"/>
<p:dialog id="addMemberDialog" widgetVar="addMemberDlg">
    <!-- More Code -->
    <p:commandButton value="Save"
        actionListener="#{memberManagedBean.save}"
        oncomplete="handleSaveNewMember(xhr, status, args)"
        update=":memberListForm:membersTable createupdateform "
        process="@form" />
</p:dialog>

..在保存按钮期间,我在此处添加一条消息,以使用咆哮组件将其显示给客户端.

..during save button, I am adding a message here to display it to the client using the growl component.

public void save(ActionEvent event) {
    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
            "Successfuly Add user", "Successfuly Add user");
    FacesContext.getCurrentInstance().addMessage(null, message);

}

我的问题是,如何对UI进行排序,以便在咆哮组件显示消息之前先隐藏对话框?

My problem is, how can I sequence the UI such that, i should hide the dialog first before the growl component could show the meesage?

function handleSaveNewMember(xhr, status, args) {
    addMemberDlg.hide();
    //update the growl after the dialog was hidden?
}

正在发生的是,咆哮声组件同时显示在对话框旁边.

What's happening is that the growl component is displayed alongside the dialog at the same time.

谢谢.

推荐答案

您可以使用PrimeFaces的 .

You can use PrimeFaces' <p:remoteCommand> for this.

<p:remoteCommand name="updateGrowl" update="showmessage" />

将被调用为

<p:commandButton ... oncomplete="addMemberDlg.hide(); updateGrowl();" />


这种特殊情况下,有一种更简单的方法.将<p:growl>autoUpdate属性设置为true.


In this particular case there's however a simpler way. Set the autoUpdate attribute of <p:growl> to true.

<p:growl autoUpdate="true" life="1500" id="showmessage"/>

它会在每个ajax请求中自动更新.如果您的组件实际上不支持它,那么您始终可以将其包装在也支持该属性的<p:outputPanel>中.

It'll auto-update itself on every ajax request. If your component actually didn't support it, then you could always wrap it in a <p:outputPanel> which also supports that attribute.

<p:outputPanel autoUpdate="true">
    ...
</p:outputPanel>

这篇关于如何从Primefaces中的javascript触发组件刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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