Cristian
Cristian

Reputation: 1670

How to update primefaces attribute?

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.

Upvotes: 0

Views: 456

Answers (1)

sinclair
sinclair

Reputation: 2861

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;" />

Upvotes: 1

Related Questions