我目前有一個文件上傳系統,目前我有一個按鈕讓用戶進入下一頁,但即使用戶沒有上傳任何內容,這也是可見的,如果用戶按下這個鍵,危險就在這裏上傳任何東西之前它會拋出一個錯誤,看起來不好,所以我想要做的就是隱藏這個按鈕,直到文件上傳成功實現,任何想法如何?如何在操作完成之前隱藏按鈕? Primefaces
<p:fileUpload widgetVar="upload" fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced"
multiple="false"
update="messages"
label="Select File"
sizeLimit="100000000"
allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf|html)$/"
auto="true"/>
<!-- selected auto="true" this has been selected to prevent user error as was discovered
when testing, some users pressed the upload button and wondered why nothing worked instead of
select file, now this stops this -->
<p:growl id="messages" showDetail="true"/>
Please press the button below once you have uploaded the file, to continue
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" ajax="False"/>
行動的命令按鈕旁邊是一個我想禁用,直到文件上傳完畢
編輯:
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" ajax="False" disabled="#{!fileUploadController.UploadComplete}"/>
是我的命令按鈕,它指向的fileUploadContoller,這是文件上傳發生的地方等,
問題是當我運行應用程序,我總是在頁面加載時得到一個實時按鈕
我添加了一個布爾到我fileUploadController:
public void handleFileUpload(FileUploadEvent event) {
//System.out.println("DesintationPDF : " + destinationPDF);
System.out.println("called handle file");
System.out.println("Destination is : " + configProp.getProperty("destination"));
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded."); //Displays to user on the webpage
FacesContext.getCurrentInstance().addMessage(null, msg);
try {
copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
} catch (IOException e) {
//handle the exception
e.printStackTrace();
}
}
public boolean isUploadComplete() {
return uploadComplete;
}
public void setUploadComplete(boolean uploadComplete) {
this.uploadComplete = uploadComplete;
}
,但仍然得到錯誤
編輯2:
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{!fileUploadController.uploadComplete}"/>
控制檯
INFO: Upload complete value before copy file false
INFO: upload complete value is : true
所以它是將該值更改爲true
但不改變按鈕生存
什麼有關禁用按鈕,啓用它,當上傳完成?似乎比突然渲染更直觀。我也建議你使用PrimeFaces,因爲它很棒。 (但這只是一個額外的東西) – Zhedar 2013-02-17 16:05:15
這將是一個完美的解決方案,我目前使用primefaces來創建fileupload和按鈕也是primefaces,我將如何去禁用和重新啓用它?將發佈我當前設置的代碼 – user2065929 2013-02-17 16:08:33
'#{navigationBean.naviagtion}「'有可能是一個輸入錯誤 – Zhedar 2013-02-17 16:11:42