biggtor
biggtor

Reputation: 47

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

I'm trying to make a a "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. If I put as callback something like onclick="alert('hello!')" the request is sent. Does PrimeFaces generates some sort of JS code that controle if submit button is disabled?

Any help? Thanks!

PrimeFaces 3.3.1

Liferay 6.0.1 with embedded Tomcat 7.0.23 in a Java6

PrimeFaces Liferay Bridge 3.1.1-ga2

Upvotes: 0

Views: 1798

Answers (1)

Daniel
Daniel

Reputation: 37061

If I got you right try using 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...

Upvotes: 2

Related Questions