How to enable / disable a JSF Command Button


The scenario looks like this:

There are two buttons in the screen, say button1 and button2. On page load, button2 is disabled. When the user clicks button1, button2 will be enabled. I achieved this functionality using javascript window.onload event, and onclick event on button1. My problem is, when the user clicks button1 it triggers a page reload. With that being said, after the reload of the page, button2 is disabled because of the onload event.

Is there another way to achieved this functionality?

By the way I'm using primefaces.

Best Solution

primeface page goes like this,

 <p:commandButton update="panel1"  actionListener="#{bean.button1}" value="button1" disabled="#{bean.disable}"> 
     <f:setPropertyActionListener value="#{false}" target="#{bean.disable}"/>   

 <p:commandButton update="panel2"  actionListener="#{bean.button2}" value="button1" disabled="#{!(bean.disable)}"> 
     <f:setPropertyActionListener value="#{true}" target="#{bean.disable}"/>    

Manage Bean:

 public class Bean {

    private boolean disable;

    // default constructor 
    public Bean(){
       this.disable= false;

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