user2065929
user2065929

Reputation: 1095

p:commandbutton doing the opposite of what i require

I have been trying to have a disabled button until and action is complete and then this should enable the button

The code for the button :

<p:commandButton action="#{navigationBean.naviagtion}"   value="Next" disabled="#{!fileUploadController.uploadComplete}"/>

This is the bean FileUploadController it is a managed and view scoped bean

    private boolean uploadComplete;

            uploadComplete = false;
            System.out.println("Upload complete value before copy file " + uploadComplete);
            copyFile(event.getFile().getFileName(), event.getFile().getInputstream());


        } catch (IOException e) {
//handle the exception
            e.printStackTrace();
        }

    }



    public void copyFile(String fileName, InputStream in) throws IOException {
        try {
            uploadComplete = true;

//does things 

    public boolean isUploadComplete() {
        return uploadComplete;
    }

    public void setUploadComplete(boolean uploadComplete) {
        this.uploadComplete = uploadComplete;
    }

In the console i have set it to out print at each time uploadComplete changes from false to true and i get :

INFO: Upload complete value before copy file false
INFO: upload complete value is : true

As you can see the value changes from false to true, the issue is the button never becomes active again, why is this ?

This works just fine, no errors etc, it is just the button issue

EDIT :

After some testing i have found with this code:

<p:commandButton id="Nav" action="#{navigationBean.naviagtion}"   value="Next"  ajax="False" update ="Nav" disabled="#{fileUploadController.uploadComplete}"/> 

it makes the button live on start up but when i upload the file it and click on the button it refreshes the page and then becomes disables, the exact oposite of what i want to happen lol, so how can this action be reveresed ? i have tried swapping around the true and false statements but this did not work, this never made the button disabled

How can i flip the controls so it does the opposite of what is doing now

Upvotes: 3

Views: 137

Answers (1)

Zhedar
Zhedar

Reputation: 3510

After our latest conversation I had a look at the official documentation.
I found that, like Sujoy commented, p:fileOupload has an attribute update, that renders a component after the upload has finished. So you update your Nav via adding update="Nav" to your <p:fileUpload>. This way your button should be re-rendered properly.
Also maybe you should switch disabled="#{fileUploadController.uploadComplete}"/> back to disabled="#{!fileUploadController.uploadComplete}"/> since if uploadComplete == true, the button should not be disabled.
You have to place update in the upload-component, not in the button itself!
Hopefully your testing hasn't messed up your code ;)

Upvotes: 1

Related Questions