Search code examples
jsfprimefacesjavabeanscommandbutton

Change value of bean when using p:commandButton


The value of the bean does not change when I have finisehd clicking on the button. I havent't any errors, but it does not work: the "locked" is still evaluated to false

Here is the code:

    <p:column>
         <p:commandButton id="downloadLink"  ajax="false"  oncomplete="#{dmFile.setLocked(true)}">
             <p:fileDownload value="#{downloadBean.downloadXMLFile(dmFile)}"  />  
        </p:commandButton> 

     <p:column headerText="lock" style="width:2%">
            <h:outputText value="#{dmFile.locked}" />              
     </p:column>   

And my bean is

    public class DMFile{

          private boolean locked;

          public boolean isLocked() {
               return locked;
          }

          public void setLocked(boolean locked) {
              this.locked = locked;
           }

    }

Solution

  • From the reference guide, the attribute oncomplete does:

    • Client side callback to execute when ajax request is completed.

    You can't reference to a bean action! It's used, for example, to call a JavaScript method and executed by the client.

    Full reference can be found HERE.