P: commandbutton does the opposite of what I need
I am trying to disable a button until the action is complete and then this should enable the button
Button code:
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{!fileUploadController.uploadComplete}"/>
This is the FileUploadController bean, it is managed and scoped by the 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 set it to print on every uploadComplete run 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 problem is that the button is never activated again, why is that?
This works fine, no errors etc, it's just a button issue
EDIT:
After some testing I 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 startup, but when I load the file and click on the button, it refreshes the page and then becomes disabled, the exact prop for what I want to happen lol, so how can this action be gleaned? i tried swapping true and false assertions but it didn't work it never caused the button to be disabled
How can I flip the controls so that it does the opposite of what is currently being done
source to share
After our last conversation, I went through the official documentation.
I found that, as Sujay said, p:fileOupload
has an attribute update
that displays the component after the download is complete. So you update Nav
yours update="Nav"
by adding to <p:fileUpload>
. This way your button should be rendered correctly.
Also, perhaps you should switch disabled="#{fileUploadController.uploadComplete}"/>
to disabled="#{!fileUploadController.uploadComplete}"/>
, since if uploadComplete == true
, the button shouldn't be disabled.
You should place the update in the upload component, not in the button itself!
Hope your testing hasn't messed up your code;)
source to share