Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Problems with multiple click on a button

Egil Sørensen
1 decade ago Feb 04, 2011 12:50pm

Hi, is it possible to disable multiple clicks on the same button while the server is running the request?

In our case we have a button that generates a report that takes typically 15-20 seconds to generate. As we have quite a few users that are not of the most patient type they will click the button again as there is no immediate result.

If I understand the underlying architecture correctly, this new request will be queued and then sent to the server when the previous request completes? Is it possible to override this behavior? In simple HTML we would either disable the button with javascript and/or enforce this with a servlet filter checking if there is already an undergoing action. However, we are not able to do this now as requests come in to the server back-to-back as they do now.

There have to be others who have the same problem as us, even if it is just to control if a user has double-clicked a button instead of a single click. Some operations in our application will also behave differently if run twice instead of once (transactions generated two times for instance).

Thanks!

Artur Signell
1 decade ago Feb 04, 2011 3:51pm
Egil Sørensen
1 decade ago Feb 07, 2011 4:35am
Egil Sørensen
1 decade ago Feb 09, 2011 7:15am
David Wall
1 decade ago Feb 09, 2011 4:53pm
Egil Sørensen
1 decade ago Feb 10, 2011 7:02am

My point exactly.

We tried the solution of manually making the button disabled from the java code and then spawn another working thread. However, there is simply no chance that this operation is fast enough to avoid double clicks (and if it was in our test environment, it could definitely not guarantee it for all instances).

So basically what we need is a way to set the property on a button (or a form) to disable button(s) while loading on the server. Shouldn't be too hard to implement either.

In good old (yeah, I'm one of those...) times, a simple $(input[type=button]).attr("disabled", true); would suffice... Then set it to false when the callback (or timeout) is run...

Last updated on Feb, 10th 2011
Artur Signell
1 decade ago Feb 10, 2011 9:00am
Egil Sørensen
1 decade ago Feb 10, 2011 9:45am
Artur Signell
1 decade ago Feb 10, 2011 10:03am
Egil Sørensen
1 decade ago Feb 14, 2011 8:21am
Marlon López Meza
1 decade ago Feb 21, 2011 5:09pm
Artur Signell
1 decade ago Jul 18, 2011 1:10pm

Button.setDisableOnClick(boolean) was committed to the 6.7 branch today so be sure to check out the next nightly for this feature.

David Tramer
10 years ago Oct 25, 2012 11:17pm
Kirk Rasmussen
9 years ago Jul 10, 2013 7:27pm
Henri Sara
9 years ago Jul 11, 2013 6:50am
Kirk Rasmussen
9 years ago Jul 17, 2013 11:06pm
Henri Sara
9 years ago Jul 18, 2013 6:07am
Kirk Rasmussen
9 years ago Jul 18, 2013 5:11pm
Stephen Bu
8 years ago Oct 23, 2014 8:04pm
David Wall
8 years ago Oct 23, 2014 10:16pm
Stephen Bu
8 years ago Oct 23, 2014 10:43pm
Laurent De Laprade
6 years ago Feb 26, 2017 12:37pm
Stephan Grenier
5 years ago Dec 13, 2017 5:18am
Bagus Priyo Wibowo
4 years ago Oct 26, 2018 2:54am

How to make a button move page, just move page..... i am so confuse about that.. sorry iam is newbie developer with vaadin, so can you help me???

sorry i talk in english so poor....

Farrukh Ijaz
4 years ago Nov 16, 2018 12:55pm

Just in case if someone is still facing this issue, I fixed it by implementing custom click listeners and one of them is as follows:

public abstract class TRButtonClickListener implements Button.ClickListener, Serializable {

	private static final long serialVersionUID = 1L;

	private long sleepDuration = 250L;
	volatile boolean isFired = false;

	@Override
	public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
		if (!isFired) {
			synchronized (this) {
				if (!isFired) {
					isFired = true;
					try {
						onButtonClick(event);
					} finally {
						Executors.newSingleThreadExecutor().execute(() -> {
							try {
								Thread.sleep(sleepDuration);
							} catch (InterruptedException e) {
							} finally {
								isFired = false;
							}
						});
					}
				}
			}
		}
	}

	public TRButtonClickListener withSleepDuration(long sleepDuration) {
		this.sleepDuration = sleepDuration;
		return this;
	}

	public abstract void onButtonClick(com.vaadin.ui.Button.ClickEvent event);
}

and using it as follows:

Button button = new Button("Click Me!", new TRButtonClickListener() {
	@Override
	public void onButtonClick(ClickEvent event) {
		System.out.println("This will get fired only once.");
	}
});