• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to implement this requirement

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to design a module which has this requirement.

A html page where users specifies the amount to be deducted by entering the amount in a textbox and presses deduct button. But if the user presses this deduct twice accidentally the amount will be deducted twice from his account. This should be prevented.

I tried disabling the Deduct button once the user presses it using javascript code. But this solution did not work in netscape browser. Is there any better solution to this problem ?

[ December 06, 2006: Message edited by: Satish Kota ]
[ December 06, 2006: Message edited by: Satish Kota ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using transaction management
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to associate your request object with a unique key and a boolean variable. You will also have to maintain a hashtable at the application scope which will keep a record of which unique key is associated with which request. Request object is a hash, so you can set and get objects on your will. So as soon as a request is submitted you need to get the unique key and request id from the request check in the application scopes hashtable to crosscheck if it is the correct key. If the authentication passes set the boolean variable to true. Now true will signify that this request is submitted. so everytime you will have to check for the boolean variable to see if the request is already submitted. If the request is already submitted do not perform any action.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Johnson Abraham:
You will have to associate your request object with a unique key and a boolean variable. You will also have to maintain a hashtable at the application scope which will keep a record of which unique key is associated with which request. Request object is a hash, so you can set and get objects on your will. So as soon as a request is submitted you need to get the unique key and request id from the request check in the application scopes hashtable to crosscheck if it is the correct key. If the authentication passes set the boolean variable to true. Now true will signify that this request is submitted. so everytime you will have to check for the boolean variable to see if the request is already submitted. If the request is already submitted do not perform any action.




Technically Johnson's suggestion can be implemented by the following way.

Client ckilks submit button.
Below is the algorithm that is to be implemented at the servlet code that intercepts the client request.

session = request.getSession(false);
if(session != null){
String firstClick = session.getAttribute("FIRST_CLICK");
if(firstClick.equals("SET")){
//this is second click of the button.
//take appropriate action.
}else{
session.setAttribute("FIRST_CLICK","SET");
//do processing.
}
}//end of if.
 
Satish Kota
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:



Technically Johnson's suggestion can be implemented by the following way.

Client ckilks submit button.
Below is the algorithm that is to be implemented at the servlet code that intercepts the client request.

session = request.getSession(false);
if(session != null){
String firstClick = session.getAttribute("FIRST_CLICK");
if(firstClick.equals("SET")){
//this is second click of the button.
//take appropriate action.
}else{
session.setAttribute("FIRST_CLICK","SET");
//do processing.
}
}//end of if.



When should i reset the FIRST_CLICK attribute in session. Because if i don't reset FIRST_CLICK i will be unable to do any more submission!
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After the processing , remove value "SET" from session.
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satish,

You want user not to press "Deduct" button in his session time or you don't want him press continously twice?

Thanks,
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do one thing.
When you type the URL in the address bar to access your web-application, initially,

1) create a session object.
HttpSession session = request.getSession(true);

2) take a boolean value boolValue and assign it as false.
boolean boolValue = false;

3). Convert this 'boolValue' into 'Boolean object'.
To do this, take a Boolean wrapper class and pass boolValue as an
argument.

Boolean b = new Boolean(boolValue);

4) Now set this Boolean object 'b' as an attribute of session.

session.setAttribute("boolValue_attribute",b);

Now let us come to your problem.....
When your form is submitted, some value is deducted from the database.
When the form is again submitted, the value should not be deducted.

To solve this....

When your form is submitted, request goes to the web-container, and corresponding servlet is executed.
Now into this servlet write the following code.

5). HttpSession session = request.getSession(true);

(I think you know -the purpose of this method.
Because we are passing 'true' value as an attribute of
getSession() method,the web-container checks whether the session
object is created previously or not.
If the session object is already created, it returns the
reference of the object.
If the session object is not created earlier, web-container
creates a new session object).

(Here, in our case, because of the code at line 1, the session
object is already created.
so the above code at line 5, returns the reference of the
existing session object).

5). Now get the value of the 'boolValue_attribute' from session object.

Boolean b1 = (Boolean) session.getAttribute("boolValue_attribute");

(This method returns value of type Object. So we have typecasted
this value into Boolean).

6). Now get the actual value from Boolean object.
To get the wrapped value -
boolean b2 = b1.booleanValue();

7). Now let us compare b2 with false.
if (b2 == false)
{
// code to deduct the value .

booleValue = true; // you must set this 'boolValue' to 'true'.

Boolean b = new Boolean(boolValue);
session.setAttribute("boolValue_attribute",b);
}


8) Now in this case previously
boolValue = false.
But after the form is submitted, and after the if condition is executed,
boolValue = true;

9). Now in this situation, if you submit the form once again, because
the boolValue = true, If condition will not be executed. and the
transaction will not be done.
(i.e, the value will not be deducted once again).

Finally it solves your problem
bye.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use javascript to do this. After the user press the button first time , using javascipt to disable the button. When the user click the button second time, there will be nothing happen(No form will be sent to the server).
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a J2EE pattern i think Session Token, it deals with the web application flow. It will also help you with the browser's back button and things like that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic