Java 如何隐藏按钮直到操作完成?素面
我目前有一个文件上传系统,目前我有一个按钮可以将用户带到下一页,但即使用户没有上传任何东西,这也是可见的,危险在于如果用户在上传任何东西之前按下此按钮,它将抛出错误,看起来很糟糕,所以我要做的是隐藏这个按钮,直到文件上传成功,你知道怎么做吗Java 如何隐藏按钮直到操作完成?素面,java,jsf,file-upload,primefaces,Java,Jsf,File Upload,Primefaces,我目前有一个文件上传系统,目前我有一个按钮可以将用户带到下一页,但即使用户没有上传任何东西,这也是可见的,危险在于如果用户在上传任何东西之前按下此按钮,它将抛出错误,看起来很糟糕,所以我要做的是隐藏这个按钮,直到文件上传成功,你知道怎么做吗 <p:fileUpload widgetVar="upload" fileUploadListener="#{fileUploadController.handleFileUpload}"
<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"/>
但是仍然得到了错误
编辑2:
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{!fileUploadController.uploadComplete}"/>
因此,它正在将值更改为true
但是没有将按钮更改为活动按钮使下一个按钮不可见。在开始时维护一个flag=false,成功上载文件后,将该标志设置为true。或者在文件上传结束时,使“下一步”按钮为true 上传完整事件集时显示=块 HTML
实时演示:要在上传完成之前禁用按钮,只需将
disabled
属性绑定到bean中的属性即可。在我看来,禁用似乎比突然渲染更直观。用户也会知道在后台发生了一些事情
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{bean.disable}" ajax="False"/>
上传完成后,如何禁用按钮并启用它?对我来说,似乎比突然渲染要直观得多。我还建议你使用PrimeFaces,因为它很棒。(但这只是另外一件事)这将是一个完美的解决方案,我目前正在使用primefaces创建文件上传,按钮也是primefaces,我将如何禁用和重新启用它?将发布我当前设置的代码
{navigationBean.naviagtion}
其中可能有一个输入错误。{navigationBean.naviagtion}
指向我拥有的一个java bean,它将用户带到另一个页面,该属性当前工作正常。该属性名为naviagtion
?不是navigation
?谢谢,我该怎么做?谢谢,我该如何将disable属性绑定到正在完成文件上传的bean?只需在navigationBean
中添加另一个boolean
属性,例如将其命名为uploadComplete
。上传完成后,将其设置为true
。在您的按钮中,它将是:disabled=“#{!navigationBean.uploadComplete}”
对不起,我是新手,添加另一个布尔属性是什么意思,您有示例吗?谢谢,我尝试了一个问题,现在遇到了一个错误,编辑了原始问题以显示我的代码和错误,我做错了什么?当然属性必须命名为isUploadComplete()
而不是isComplete()
。我的错。
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{!fileUploadController.uploadComplete}"/>
INFO: Upload complete value before copy file false
INFO: upload complete value is : true
<form action="#" method="post">
<input type="file" name="fileInput" id="fileInput" />
<input type="submit" id="submitbutton" value="submit" style="display:none" />
</form>
<div id="result"></div>
$(document).ready(
function(){
$('input:file').change(
function(){
if ($(this).val()) {
document.getElementById("submitbutton").style.display='block';
}
}
);
});
<p:commandButton action="#{navigationBean.naviagtion}" value="Next" disabled="#{bean.disable}" ajax="False"/>
public class YourNavigationBean {
private boolean uploadComplete; // <--- that's the property
// ... your bean content, like constructors and stuff..
// ...
//a setter and a getter is needed, to here they are
public boolean isUploadComplete() {
return uploadComplete;
}
public void setUploadComplete(boolean uploadComplete) {
this.uploadComplete = uploadComplete;
}
}