How to disable button immediately after pressing

Hi

In my save button there is a code for insertion of data in database.

In my application when i press save button first time the IE progress bar shows progress but if suppose the user presses the button again

then the data wil get saved twice.

Now if i put a code in button action method to disable it will function only when it will be called in between user can press the button.

How to arrest users for clicking?

If you have any idea please help me out.

[500 byte] By [anikhindia] at [2007-11-26 21:24:03]
# 1

How about setting the button to:

yourButton.setVisible(false);

So when your button action is called, this is the first action that is called before your code insertion lines so the button will disappear when clicked e.g.

public String yourButton_action {

yourButton.setVisible(false);

....code insert data......

return null;

}

Or set the "return null" to return a new page.

Of course, if you wanted it to be visible again after the insertion then you would set

yourButton.setVisible(true);

Alternatively, you could setup a counter that would check the number of times the button was pressed and make the button visible (or invisible!) when conditions are met.

aerostraa at 2007-7-10 3:03:54 > top of Java-index,Development Tools,Java Tools...
# 2

Ya its a good idea but there are two aspects of this hiding the button

1. Its OK to hide button from user but still if the request for hiding goes long the user can press once again.

2. It is not looking good to hide the button as a business software perspective so i am trying to disable it but .... the request for disabling goes longer i have set a counter for not executing DB insertion code once againbut again in catch i will clear the counter and after successfull insertion i will clear the counter but the condition for that should be it will be a static counter.

anikhindia at 2007-7-10 3:03:54 > top of Java-index,Development Tools,Java Tools...
# 3

Before displaying page to user generate some unique id and put it in hidden field. When user submits page store value from this hidden field in session bean. After transaction finish remove value from session bean. So if user will submit same page for second time, just check value in session bean and if they are equal ignore request.

hope this helps.

best regards

Grzegorz

Grzegorz.Kluczeka at 2007-7-10 3:03:54 > top of Java-index,Development Tools,Java Tools...
# 4
But if user clicks button in between running transaction as the save button is visible and background database process is running the value in session bean will be valid and code wlll run again ....
anikhindia at 2007-7-10 3:03:54 > top of Java-index,Development Tools,Java Tools...