3

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?

JulianG
  • 1,551
  • 1
  • 19
  • 29
yetAnotherSE
  • 3,178
  • 6
  • 26
  • 33
  • 1
    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. – Aritz Oct 04 '13 at 07:55
  • I reproduced your code and it's perfectly working for me. – Konstantin Yovkov Oct 04 '13 at 08:02
  • @XtremeBiker I tried it also ( setting it in normalize method) but it is not working also. – yetAnotherSE Oct 04 '13 at 08:21
  • Sorry it is about line: disabled="#{!(bean.disable)}"> it should be mainTable.disable Problem solved. – yetAnotherSE Oct 04 '13 at 08:27
  • 1
    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. – Aritz Oct 04 '13 at 08:43
  • I think instead of `disabled="#{!(myTable.disable)}">` you mean `disabled="#{!(mainTable.disable)}">`? If that's the case, you might edit the question, or add your own answer and accept that one. – Wisco crew Apr 23 '14 at 17:17
  • This question appears to be off-topic because it is about thoughtfulness mistake. – yetAnotherSE Jun 06 '14 at 08:03

2 Answers2

5

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)}">

JulianG
  • 1,551
  • 1
  • 19
  • 29
  • Any error message? Maybe try to wrap the two buttons in a container like the primefaces outputPanel (`p:outputPanel`) – JulianG Oct 04 '13 at 08:02
  • Did my answer helped you? I see you solved it, but without updating the button it shouln't be working. – JulianG Oct 04 '13 at 08:34
1

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>
Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53