如何更新primefaces属性?

时间:2016-09-13 06:16:50

标签: jsf primefaces disabled-input ajax-update

我有<p:commandButton disabled="#{scannerStatus.disabled}" actionListener="#{scannerStatus.activate}" id="button-id"/>

在scannerStatus中我有:
private boolean disabled; //加上geters和setter

public void activate() {
        this.setDisabled(true);
        boolean status = doAnAction(); // This takes some seconds

        if (!status) {
            doSomething();
        } else {
            this.setDisabled(false);
        }
    }

问题是,当调用disabled方法的this.setDisabled(true)行时,commandButton的activate属性不会改变。

我需要几秒钟将commandButton中的disabled属性设为true

disabled属性设置为false,然后更新commandButton中的disabled属性。因此commandButton中的更新发生在函数结束之后。

当方法中的this.setDisabled(true)激活时,如何更新commandButton的属性?

我试过用 RequestContext.getCurrentInstance().update("button-id");
this.setDisabled之后,但它无效。

1 个答案:

答案 0 :(得分:1)

未经测试,但这样的事情应该这样做:

<p:commandButton 
 actionListener="#{scannerStatus.activate}" 
 id="button-id"
 onstart="document.getElementById('button-id').disabled = true;"
 oncomplete="document.getElementById('button-id').disabled = false;" />