In scannerStatus I have: pr" /> In scannerStatus I have: pr" /> In scannerStatus I have: pr"/>

How to update primefaces attribute?

441 views Asked by At

I have a <p:commandButton disabled="#{scannerStatus.disabled}" actionListener="#{scannerStatus.activate}" id="button-id"/>

In scannerStatus I have:
private boolean disabled; // plus geters and setters

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

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

The problem is that the disabled attribute of the commandButton does not change when this.setDisabled(true) line from activate method is called.

I need some seconds the disabled attribute from the commandButton to be true.

The disabled property is set back to false and then the disabled attribute from commandButton is updated. So the update in commandButton takes place after the function ends.

How can I update the attribute of the commandButton when the this.setDisabled(true) in the method activate?

I have tried to use
RequestContext.getCurrentInstance().update("button-id");
after the this.setDisabled but it's not working.

1

There are 1 answers

0
sinclair On

Not tested, but something like this should do it:

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