2

If I initiate a commandButton disabled it does not fire even after re-enabling the button.

<p:commandButton id="btnAJAX" value="AJAX" widgetVar="btnAJAX" disabled="true" action="#{bean.neverReached()}"/>
<p:commandButton id="btnEnabler" value="Enable" oncomplete="btnAJAX.enable()"/>

Similar problem identitifed here : http://forum.primefaces.org/viewtopic.php?f=3&t=7817

I am using primefaces 3.0.1 and JDK 1.7

Is there any solution to this?

1 Answer 1

5

You need to enable the button by JSF, not by JavaScript/HTML DOM. During processing of the form submit, JSF will verify in the server side view state as well if the button is enabled or not, as part of safeguard against tampered requests.

E.g.

<p:commandButton id="btnAJAX" value="AJAX" action="#{bean.someAction}" disabled="#{!bean.enabled}" />
<p:commandButton id="btnEnabler" value="Enable" action="#{bean.enableButton}" process="@this" update="btnAJAX" />

with

private boolean enabled;

public void enableButton() {
    enabled = true;
}

public boolean isEnabled() {
    return enabled;
}

Make sure that the bean is at least @ViewScoped and not @RequestScoped, otherwise the action of button will still fail because the bean is recreated during the form submit request and thus the enabled property will become the default value, which is false.

See also:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.