如何启用/禁用primefaces commandButton?

时间:2013-10-04 07:45:33

标签: jsf jsf-2 primefaces commandbutton

屏幕上有两个按钮。当页面首次加载时我想要按钮2被禁用,直到单击按钮1。 单击button1时,必须启用button2。

我试过了:

<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>

我的豆子:

@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;
    }
}

但它不起作用。单击button1时,按钮2仍处于禁用状态。 有什么问题?

2 个答案:

答案 0 :(得分:4)

尝试更新第二个按钮,点击第一个按钮,如dataTable


您应该使用bean =&gt;替换disabled="#{!(bean.disable)}">中的mainTable disabled="#{!(mainTable.disable)}">

答案 1 :(得分:1)

您应该在Outputpanel中交换2个按钮,并将此输出面板更改为下一个按钮,如下所示:

<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>