Disabled button container onClick

Hey Guy’s,
I’ve been stuck trying to get something to work for quite some time now, so if anyone could point me in the right direction and suggest a new approach i would really appreciate it.

I’m trying to disable a set of buttons if any of them is clicked and keep them disabled until the first buttons operation has completed. I’ve tried a bunch of things but i just can’t seem to force an update immediately and not have the UI updates queued with the other requests but rather immediately disable the layout (similar to the new button.disableOnClick functionality) and re-enable it upon completion.

Any assistance would be appreciated.

Thanx
Marko


public Component getTest() {
		VerticalLayout VL = new VerticalLayout();
		
		for (int x = 0; x < 3; x++) {
			Button button = new Button(x+"");
			button.addListener(new ClickListener() {
				
				public void buttonClick(ClickEvent event) {
					Button sourceB = event.getButton();
					sourceB.getParent().setEnabled(false);
					sourceB.getParent().requestRepaint();
					
					try {
						Thread.sleep(2000); // Long operation
					} catch (InterruptedException e) {} 
					
					sourceB.getParent().setEnabled(true);
				}
			});
			VL.addComponent(button);
		}
		
		return VL;
	}

I’m sorry if I understood something incorrectly, but at least in the example you provided, the code is blocking the thread so no updates are sent to client side during the simulated long operation.

In case of asynchronous operations I would not rely on UI element state as a way of preventing application’s services to be called, instead I would use some server side flag or state object to determine whether an operation is allowed or not. Disabling buttons in the UI would be just for usability.

Hi,
Yes the code is blocking the thread to simulate a db read operation or another long running process. Each button would open a modal window and allow the user to do something in the window, so if i have 5 buttons and the user click button 1, while the modal window for button 1 is being generated (eg. a read is done on the db) i do not want the user to click the other 5 buttons and end up having all 5 windows open, so block any client requests to the server until modal window 1 is displayed and closed. Hope that explains it better.

Cheers

Hi Marko!

Have you considered doing the db operation (or whatever the long running task is) in a separate Thread? Just disable all other buttons before you execute this threaded task. About task scheduling see e.g. the following link
http://www.kodejava.org/examples/139.html

#johannest

In Vaadin 6.7.x you can also disable button on click, see:
http://demo.vaadin.com/sampler#ButtonDisableOnClick

This is done in the component’s client side before the click event is sent to server.

In your case, if you want to disable more than one button before operation in the server starts, that might be little bit tricky.

One way to do this might work as Johannes suggested, start a new thread for the time consuming work and leave it running in the background, then while it’s running set the layout containing the buttons disabled. This would then require using some sort of ProgressIndicator or Refresher implementation to poll the thread state from the UI side.


http://vaadin.com/directory#addon/refresher

You might also try using the ButtonGroup addon in the directory:
http://vaadin.com/directory#addon/buttongroup