简体   繁体   English

无法在表单上禁用p:commandButton进行文件上传 - PrimeFaces

[英]Can't disable p:commandButton on form for file upload - PrimeFaces

I'm trying to make aa "one-click button" to make impossible to send twice the request of an action method in a file upload form. 我试图制作一个“一键式按钮”,使得无法在文件上传表单中发送两次动作方法的请求。 Here's the code: 这是代码:

<h:form id="importForm" enctype="multipart/form-data">
   <p:messages id="messages" showDetail="true" autoUpdate="true"/>

   <h:panelGrid>            
     <p:fileUpload value="#{importController.uploadFile}" mode="simple" />

     <p:commandButton id="importButton" styleClass="commandButton" value="Send" action="#{importController.getFile}" ajax="false"/>   
   </h:panelGrid>
</h:form>

If I set the value of onclick="importButton.disable()" , the button is disabled but the action method is never called. 如果我设置onclick="importButton.disable()" ,则禁用该按钮但从不调用action方法。 If I put as callback something like onclick="alert('hello!')" the request is sent. 如果我把回调类似于onclick="alert('hello!')" ,则会发送请求。 Does PrimeFaces generates some sort of JS code that controle if submit button is disabled? 如果禁用提交按钮,PrimeFaces会生成某种JS代码吗?

Any help? 有帮助吗? Thanks! 谢谢!

PrimeFaces 3.3.1 PrimeFaces 3.3.1

Liferay 6.0.1 with embedded Tomcat 7.0.23 in a Java6 Liferay 6.0.1,在Java6中嵌入了Tomcat 7.0.23

PrimeFaces Liferay Bridge 3.1.1-ga2 PrimeFaces Liferay Bridge 3.1.1-ga2

If I got you right try using onclick="setTimeout('importButton.disable()";', 50);" , 如果我onclick="setTimeout('importButton.disable()";', 50);"对你,请尝试使用onclick="setTimeout('importButton.disable()";', 50);"

You can't expect a disabled button to work (invoke the action method) , but you can disable it after the click... 您不能指望禁用按钮工作(调用操作方法),但您可以在单击后禁用它...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM