3
votes

I have two buttons on screen. When page first loaded I want to button2 is disabled until button1 is clicked. When button1 is clicked, button2 must be enabled.

I tried:

<p:commandButton value="Normalize"
    actionListener="#{mainTable.normalize}" update="dataTable"
    id="normalize" styleClass="ui-priority-primary"
    style="font-size: 14px">
    <f:setPropertyActionListener value="#{true}"
        target="#{mainTable.disable}" />
</p:commandButton>
<p:commandButton value="To Verify Next->" action="verify.xhtml"
    actionListener="#{mainTable.verify}" id="next"
    styleClass="ui-priority-primary" style="font-size: 14px"
    disabled="#{!(bean.disable)}">
</p:commandButton>

My bean:

@ManagedBean
@SessionScoped
public class MainTable
{

    private boolean disable;

    public MainTable()
    {
        disable = false;
    }
    public boolean isDisable()
    {
        return disable;
    }

    public void setDisable(boolean disable)
    {
        this.disable = disable;
    }
}

But it doesn't work. When I clicked button1, button2 is still disabled. What is wrong?

2
Debug your code. Is the disable property being set? Also why are you using f:setPropertyActionListener tag when you have the normalize action listener? Just set it to true when normalize is called. - Xtreme Biker
I reproduced your code and it's perfectly working for me. - Konstantin Yovkov
@XtremeBiker I tried it also ( setting it in normalize method) but it is not working also. - yetAnotherSE
Sorry it is about line: disabled="#{!(bean.disable)}"> it should be mainTable.disable Problem solved. - yetAnotherSE
Glad to see it worked. Try to publish an answer for your own question instead of editing the question itself to publish the answer there. - Xtreme Biker

2 Answers

5
votes

Try to update the second button on clicking the first one like the dataTable


You should replace the bean in disabled="#{!(bean.disable)}"> with mainTable => disabled="#{!(mainTable.disable)}">

1
votes

You should swap 2 buttons in a Outputpanel, and update this outputpanel alter for next button, like this:

<p:outputPanel id="pnltest">
  <p:commandButton value="Normalize"
    actionListener="#{mainTable.normalize}" update="dataTable,pnltest"
    ...
  </p:commandButton>
  <p:commandButton value="To Verify Next->" action="verify.xhtml"
    actionListener="#{mainTable.verify}" id="next"
    ...
  </p:commandButton>
<p:outputPanel>