aspose file tools*
The moose likes JSF and the fly likes h:commandButton + actionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "h:commandButton + actionListener" Watch "h:commandButton + actionListener" New topic
Author

h:commandButton + actionListener

tito couto
Greenhorn

Joined: Sep 02, 2009
Posts: 3
Hi, I have the following code:


<h:commandButton id="exportPDFButton" actionListener="#{exportPDF.exportPDF}">

This button calls to the server who then runs the exportPDF function. This exportPDF function takes a few seconds to be done, so I want to disable the button during that time. Something like disabling the button when is clicked, and enabling back again when the function is over.
How can I achieve that? is there a way to know when the response is send?


please, any suggestion will be welcome.
Babu Subburathinam
Greenhorn

Joined: Sep 03, 2009
Posts: 7
To disable the button on click, the discussion here details the how to.

To enable the button back
1. If you are not using AJAX, then the button will be automatically enabled when the response in posted back to the browser
2. If you are using AJAX, the way to enable the button will depend on how (e.g. 3rd party libraries that you may be using) you achieve AJAX.
tito couto
Greenhorn

Joined: Sep 02, 2009
Posts: 3
Hi, thanks for the response!

I followed the steps from the link you provided me and this is the actual code:



... and the javascript:



This actual code disables the button and goes to the server, but the button is never "automatically enabled" as you said.
I am not using ajax nor submiting the page(page is never refreshed) .... at least now consciously.
any suggestion?
Babu Subburathinam
Greenhorn

Joined: Sep 03, 2009
Posts: 7
tito couto wrote:
This actual code disables the button and goes to the server, but the button is never "automatically enabled"


Since you say "goes to the server", I presume your exportPDF.exportPDF method is getting invoked. Is that right?

If so, after the method has completed execution, what does the browser status indicate? Is the browser still waiting for a response or is it gets a response but the button is disabled?
Babu Subburathinam
Greenhorn

Joined: Sep 03, 2009
Posts: 7
One more observation on your code

tito couto wrote:



The <h:commandLink ..> is embedded inside the <h:commandButton..>. I do know if this is valid and necessary. Instead try giving this a shot. This may or may not be the cause of your issue, but will be good to get it straight.


tito couto
Greenhorn

Joined: Sep 02, 2009
Posts: 3
The <h:commandLink ..> is embedded inside the <h:commandButton..>. I do know if this is valid and necessary. Instead try giving this a shot. This may or may not be the cause of your issue, but will be good to get it straight.


Tried again with your suggestion but the application behaves the same.

Since you say "goes to the server", I presume your exportPDF.exportPDF method is getting invoked. Is that right?

Yes. The method exportPDF is executed on the server with no problem.

Another thing, maybe it could help... the last lines of the exportPDF method are these


This code allows the user to download a pdf file.

If so, after the method has completed execution, what does the browser status indicate? Is the browser still waiting for a response or is it gets a response but the button is disabled?


While the exportPDF method is executing on the server, the browser behaves as is if it loading something on the page. When the exportPDF is done(runs the previous code) a download dialog box appears and the browser stops "loading".
 
jQuery in Action, 2nd edition
 
subject: h:commandButton + actionListener