Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Serveral Clicks On a Button

  Asked By: Rani    Date: Apr 26    Category: Java    Views: 717
  

In a web application based on J2EE architecture, there is button. When
you click on this button, a series of jobs will run. This process will
take place in one or two minutes. Suppose that during executing the
jobs, The user click again on this button. So, the new series of jobs
will run for the second time parallel with the first series.
How can I prevent this problem? I'm beginner in J2EE.

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Marina Smith     Answered On: Apr 26

You could use javascript to disable the button  when it was clicked and enable it when the job was done .

 
Answer #2    Answered By: Verner Fischer     Answered On: Apr 26

Have you tried disabling the button  after the first click  ?

 
Answer #3    Answered By: Luz Hayes     Answered On: Apr 26

The most simple way is to disable button  after click. To do this, add JavaScript event "onclick" like below:

<form>
<input id="submitButton" type="submit" value="Button" onclick="disableButton()"/>
</form>

<script type="text/javascript">
function disableButton()
{ document.getElementById("submitButton").disabled = true; }
</script>

If you need framework specific solutions, please let us know which framework do you use.
For example Struts2 has tokens to avoid this situations.

 
Answer #4    Answered By: Vidos Fischer     Answered On: Apr 26

if you are using J2EE stack,
since you can not use synchronized keyword in EJB components,
you have to do it in other ways, here is one of them:

then use a statefull session bean for doing this task.
put a boolean variable in your bean,
in statefull session bean check this boolean variable before starting the task and set its value
look at this example:

public Class MySFSB .... {
...
boolean isBusy = false;
...
public myMethod(...) {
if (isBusy) {
// throw exception or do some thing else like just returning from method
return;
}
isBusy = true;
// now do your job
....
....
isBusy = false;
}

 
Answer #5    Answered By: Hoor Khan     Answered On: Apr 26

You can also check the state of process  on the client side
Disable the key after clicking and Enable it at the end of process.

 
Answer #6    Answered By: Hugo Williams     Answered On: Apr 26

HTTP Requests are designed to work asynchronously. Implement synchronous (Ajax) requests to handle it.

 
Didn't find what you were looking for? Find more on Serveral Clicks On a Button Or get search suggestion and latest updates.




Tagged: