• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple submits and Struts framework

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Can Struts handle multiple submits (i.e. handling more than one requests sent from the same page)? Multiple submits occur, for example, when the user clicks one button more than once.

There is way to disable a button after one click with Java script (client side implementation). Also there is a way to catch multiple submits on the web server side (server side implementation). But the problem with the latter is that the response to the original request gets lost.

Thanks a lot in advance.
[ May 18, 2004: Message edited by: Alex Sharkoff ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts has a "session token" based implementation for preventing double-submits. I don't think it prevents your "first request's response is lost" problem, though.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lasse,

Does the session token mechanism implemented and applied automatically? Do I need to set anything in the configuration file (like validation), or it really did all things in auto?

In addition, if not, are there any code example?

Nick
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
Does the session token mechanism implemented and applied automatically? Do I need to set anything in the configuration file (like validation), or it really did all things in auto?


No, it doesn't get applied automatically. You need to call Action#saveToken(HttpServletRequest) in your Action class to mark the start of a "transaction" you want to be submitted only once. Then, when you're ready to submit the transaction, call Action#isTokenValid(HttpServletRequest, boolean) to determine whether the transaction token is still valid (if it isn't, you know that the transaction has been processed once already).

Disclaimer: I have only written some practice code using this technique so I'm not sure how well it suits real-world situations.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Action provides following vey useful methods to do this :
* isCancelled(HttpServletRequest request) { return false;}
* isTokenValid(HttpServletRequest request) { return false;}
* isTokenValid(HttpServletRequest request, boolean reset) { return false;}
* resetToken(HttpServletRequest request) { }

Here is the code sample. Implement this in your base action class.
==========================================================================
if (form instanceof BaseActionForm &&
"true".equalsIgnoreCase( ( (BaseActionForm) form).getUseToken()))
{
if (isTokenValid(request)||
(request.getSession().getAttribute(Globals.TRANSACTION_TOKEN_KEY) == null)) {
forward = processCurrentRequest(mapping, form, request, response);
}else {
resetToken(request);
request.setAttribute("errorkey", "error.generic.1");
forward = ERRORPAGE;
}
} else { //Use Token is set to false (default) or not of type BaseActionForm
forward = processCurrentRequest(mapping, form, request, response);
}
===========================================================================
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But then, if there are 10 actions that the system needs to serve, I need to write the checking code for 10 times?

Since each time we may need to handle different things, and focus on different areas, are there any methods that are declarative, not programmatic?

Nick
 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't think it is possible to implement the declarative token control,because it is embended witin your code,the machanism for token control is a little like the transaction control that the code is enclosed in the "begin..............commit" block,this machanism can give you more progem flexibility.
 
reply
    Bookmark Topic Watch Topic
  • New Topic