You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Hansjörg Meuschel <hj...@gmx.de> on 2006/01/24 18:02:51 UTC
how do I prevent nervous users starting actions more than once???
Hi,
how can I prevent impatient users of my webapp to perform actions twice
by clicking serveral times on the commandbuttons ??
- I've tried a (client-side) solution like the following, but that does
not seem to be too good :-)
Is there any better possibility?
Greets Hans
------
(javascript)
var blocked = false;
function block() {
if (blocked) { return false; }
blocked = true;
return true;
}
...
<t:commandButton onClick="return block();"/>
...
Re: how do I prevent nervous users starting actions more than once???
Posted by Craig McClanahan <cr...@gmail.com>.
On 1/24/06, Simon Kitching <sk...@apache.org> wrote:
> Well, the only way to prevent the form being *submitted* multiple times
> is with a client-side solution. It would be nice for this to be
> integrated into the command components - I'll raise a JIRA enhancement
> for this.
>
> On the server side, there are a couple of issues.
>
> The first is that the view is not thread-safe, so having multiple
> submits for the same user/view running concurrently is bad news. This
> can be fixed by having a filter that does
> synchronized(userSession) { call jsf stuff }
> Again it would be nice if MyFaces did this automatically.
>
Note that, if you use client side state saving, the issue is somewhat
different ... the view trees will be distinct (because they are each
restored from their own request), and they'll each get their own
copies of request scope backing beans too. Any potential collision
would occur on either session/application scope beans, or on other
resources accessed from the request scope backing beans.
> The second is that even when synchronizing the view, the first submit
> will change all sorts of state, so that the second one will cause
> interesting effects. This can be (partly) handled via a "token" or
> counter that is embedded in the page and is verified against a counter
> in the user session; if they get out-of-sync then the user is using the
> back button in the browser or sending multiple submits. As another email
> indicated, structs/shale has some support for this.
>
One could argue that an implementation of server side state saving
should never vend the same view tree more than once, but that would
have interesting implications on what to do with back buttons.
> Regards,
>
> Simon
>
Craig
Re: how do I prevent nervous users starting actions more than
once???
Posted by Simon Kitching <sk...@apache.org>.
Well, the only way to prevent the form being *submitted* multiple times
is with a client-side solution. It would be nice for this to be
integrated into the command components - I'll raise a JIRA enhancement
for this.
On the server side, there are a couple of issues.
The first is that the view is not thread-safe, so having multiple
submits for the same user/view running concurrently is bad news. This
can be fixed by having a filter that does
synchronized(userSession) { call jsf stuff }
Again it would be nice if MyFaces did this automatically.
The second is that even when synchronizing the view, the first submit
will change all sorts of state, so that the second one will cause
interesting effects. This can be (partly) handled via a "token" or
counter that is embedded in the page and is verified against a counter
in the user session; if they get out-of-sync then the user is using the
back button in the browser or sending multiple submits. As another email
indicated, structs/shale has some support for this.
Regards,
Simon
On Tue, 2006-01-24 at 18:02 +0100, Hansjörg Meuschel wrote:
> Hi,
> how can I prevent impatient users of my webapp to perform actions twice
> by clicking serveral times on the commandbuttons ??
> - I've tried a (client-side) solution like the following, but that does
> not seem to be too good :-)
>
> Is there any better possibility?
> Greets Hans
>
>
> ------
> (javascript)
> var blocked = false;
>
> function block() {
> if (blocked) { return false; }
> blocked = true;
> return true;
> }
>
>
>
> ...
> <t:commandButton onClick="return block();"/>
> ...
[Token / Shale] Re: how do I prevent nervous users starting actions more than once???
Posted by Matthias Wessendorf <mw...@gmail.com>.
Hansjoerg-
not used on my own, but Shale contains a Token component for this.
I think this is equal to the *struts based* token
-Matthias
On 1/24/06, Hansjörg Meuschel <hj...@gmx.de> wrote:
> Hi,
> how can I prevent impatient users of my webapp to perform actions twice
> by clicking serveral times on the commandbuttons ??
> - I've tried a (client-side) solution like the following, but that does
> not seem to be too good :-)
>
> Is there any better possibility?
> Greets Hans
>
>
> ------
> (javascript)
> var blocked = false;
>
> function block() {
> if (blocked) { return false; }
> blocked = true;
> return true;
> }
>
>
>
> ...
> <t:commandButton onClick="return block();"/>
> ...
>
--
Matthias Wessendorf
Zülpicher Wall 12, 239
50674 Köln
http://www.wessendorf.net
mwessendorf-at-gmail-dot-com
Re: how do I prevent nervous users starting actions more than once???
Posted by Emily Gu <e2...@gmail.com>.
Hi Andreas,
Thanks for the detailed explaination. I will give it a try. Thanks for
your help!!
Emily
On 3/26/06, Andreas Zeller - zit-systems <an...@zit-systems.de>
wrote:
>
> Hi Emily,
>
> It's very simple actually. Instead of using <t:commandLink action="..."
> You use the actionListener="..." attribute - To your Java-action, you just
> add a paramter of type ActionEvent.
>
> Like
>
> public String myAction (ActionEvent e){
> ...
> return "bla";
> }
>
> It looks exactly like your common action method, just that it submits the
> event that is actually triggered. Now you just need to get any necessary
> information out of the event and make your application reject any following
> actions that are not allowed now. You want to disable the buttons, I know...
> But that'll happen after the request. So during the request, the user can
> still trigger actions. So what you could do, is prevent him from doing that
> inside the application, or blocking specific actions by using a state-model
> for your application.
>
> Using application states would probably be the best idea and it would be
> clean and good code, since you wouldn't need any of the things I am
> describing right now. But we're lazy and for just one action, we don't need
> a state-model. Anyway, just didn't want to leave the idea unmentioned. Back
> to the component / parameter version.
>
> Should look like this: UIParameter lParameter =
> (UIParameter)e.getComponent().getId();
> or, if you want to access the f:param you set inside the commandlink,
> you'd use something like UIParameter lParameter =
> (UIParameter)e.getComponent().findComponent("name");
>
> Hope that'll help.
>
>
> Andreas
>
>
>
> Emily Gu wrote:
>
> Hi Andreas,
>
> Thanks for your reply. Pretty much similar. Only mine is simpler. I
> have several <h:commandLink> buttons on the same page. I would like only
> allow the first button click taking effect and disable all others. And only
> allow one click for a button. Otherwise it has submitted the same form data
> many times. If you have sample code, would you please send it to me? I would
> like to see how you get the component id and identify it is from the same
> page and but a duplicated request.
>
> Thanks a lot!!
> Emily
>
>
> On 3/25/06, Andreas Zeller - zit-systems <an...@zit-systems.de>
> wrote:
> >
> > Hey Emily,
> >
> > If your Button causes your application to fail in some way, you could
> > catch that kind of bad user interaction by identifying the clicked button
> > via the component id (which is unique for each component on your page).
> > This is kind of a "dirty" solution, but if the application switches to a
> > different state, the triggered action should be "locked", so it can't be
> > accessed again, unless it won't cause any damage.
> >
> > You would do this by giving the commandButton an ID, setting an f:param
> > inside the button and getting this parameter (if you have a dynamic model
> > and need to know which button has been clicked) back in the application via
> > an ActionEvent, which is a parameter for an actionListener method.
> >
> > I had to do this for a system that locks datasets and prevents other
> > users from editing. A user should only be able to edit one record at a time.
> > If the user acts quickly and clicks several buttons on the page, that would
> > open many open records. So what I did, is catch the ID and the param, unlock
> > the records he clicked before and open only the last one for editing. If
> > your problem is similar in some way, this might be a solution. A dirty one,
> > I admit, but it works.
> >
> >
> > Andreas
> >
> >
> > Emily Gu wrote:
> >
> > Hi,
> >
> > Would you please let me know how do you know it is clicked the same
> > button so that you can provent the next click by doing this?
> >
> > Thanks,
> > Emily
> >
> >
> > On 1/25/06, Hansjörg Meuschel <hj...@gmx.de> wrote:
> > >
> > > Hi Steffen,
> > > thanks for this great information, the filter works perfectly and
> > > solved
> > > one of my biggest problems with my application !!!!!
> > >
> > > Steffen Hankiewicz wrote:
> > >
> > > >Hi Hansjörg,
> > > >
> > > >
> > > >
> > > >>how can I prevent impatient users of my webapp to perform actions
> > > twice
> > > >>by clicking serveral times on the commandbuttons ??
> > > >>
> > > >>
> > > >
> > > >I am using a servlet filter which works great here. Maybe you want
> > > to
> > > >give it a try:
> > > >
> > > >http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
> > > >
> > > >HTH,
> > > >
> > > >Steffen Hankiewicz
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Andreas Zeller - zit-systems <an...@zit-systems.de>.
Hi Emily,
It's very simple actually. Instead of using <t:commandLink action="..."
You use the actionListener="..." attribute - To your Java-action, you
just add a paramter of type ActionEvent.
Like
public String myAction (ActionEvent e){
...
return "bla";
}
It looks exactly like your common action method, just that it submits
the event that is actually triggered. Now you just need to get any
necessary information out of the event and make your application reject
any following actions that are not allowed now. You want to disable the
buttons, I know... But that'll happen after the request. So during the
request, the user can still trigger actions. So what you could do, is
prevent him from doing that inside the application, or blocking specific
actions by using a state-model for your application.
Using application states would probably be the best idea and it would be
clean and good code, since you wouldn't need any of the things I am
describing right now. But we're lazy and for just one action, we don't
need a state-model. Anyway, just didn't want to leave the idea
unmentioned. Back to the component / parameter version.
Should look like this: UIParameter lParameter =
(UIParameter)e.getComponent().getId();
or, if you want to access the f:param you set inside the commandlink,
you'd use something like UIParameter lParameter =
(UIParameter)e.getComponent().findComponent("name");
Hope that'll help.
Andreas
Emily Gu wrote:
> Hi Andreas,
>
> Thanks for your reply. Pretty much similar. Only mine is simpler. I
> have several <h:commandLink> buttons on the same page. I would like
> only allow the first button click taking effect and disable all
> others. And only allow one click for a button. Otherwise it has
> submitted the same form data many times. If you have sample code,
> would you please send it to me? I would like to see how you get the
> component id and identify it is from the same page and but a
> duplicated request.
>
> Thanks a lot!!
> Emily
>
>
> On 3/25/06, *Andreas Zeller - zit-systems*
> <andreas.zeller@zit-systems.de <ma...@zit-systems.de>>
> wrote:
>
> Hey Emily,
>
> If your Button causes your application to fail in some way, you
> could catch that kind of bad user interaction by identifying the
> clicked button via the component id (which is unique for each
> component on your page).
> This is kind of a "dirty" solution, but if the application
> switches to a different state, the triggered action should be
> "locked", so it can't be accessed again, unless it won't cause any
> damage.
>
> You would do this by giving the commandButton an ID, setting an
> f:param inside the button and getting this parameter (if you have
> a dynamic model and need to know which button has been clicked)
> back in the application via an ActionEvent, which is a parameter
> for an actionListener method.
>
> I had to do this for a system that locks datasets and prevents
> other users from editing. A user should only be able to edit one
> record at a time. If the user acts quickly and clicks several
> buttons on the page, that would open many open records. So what I
> did, is catch the ID and the param, unlock the records he clicked
> before and open only the last one for editing. If your problem is
> similar in some way, this might be a solution. A dirty one, I
> admit, but it works.
>
>
> Andreas
>
>
> Emily Gu wrote:
>
>> Hi,
>>
>> Would you please let me know how do you know it is clicked the
>> same button so that you can provent the next click by doing this?
>>
>> Thanks,
>> Emily
>>
>>
>> On 1/25/06, *Hansjörg Meuschel* <hjmeu@gmx.de
>> <ma...@gmx.de>> wrote:
>>
>> Hi Steffen,
>> thanks for this great information, the filter works perfectly
>> and solved
>> one of my biggest problems with my application !!!!!
>>
>> Steffen Hankiewicz wrote:
>>
>>>Hi Hansjörg,
>>>
>>>
>>>
>>>>how can I prevent impatient users of my webapp to perform
>> actions twice
>>>>by clicking serveral times on the commandbuttons ??
>>>>
>>>>
>>>
>>>I am using a servlet filter which works great here. Maybe
>> you want to
>>>give it a try:
>>>
>>> http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
>>>
>>>HTH,
>>>
>>>Steffen Hankiewicz
>>>
>>>
>>>
>>>
>>
>>
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Emily Gu <e2...@gmail.com>.
Hi Andreas,
Thanks for your reply. Pretty much similar. Only mine is simpler. I
have several <h:commandLink> buttons on the same page. I would like only
allow the first button click taking effect and disable all others. And only
allow one click for a button. Otherwise it has submitted the same form data
many times. If you have sample code, would you please send it to me? I would
like to see how you get the component id and identify it is from the same
page and but a duplicated request.
Thanks a lot!!
Emily
On 3/25/06, Andreas Zeller - zit-systems <an...@zit-systems.de>
wrote:
>
> Hey Emily,
>
> If your Button causes your application to fail in some way, you could
> catch that kind of bad user interaction by identifying the clicked button
> via the component id (which is unique for each component on your page).
> This is kind of a "dirty" solution, but if the application switches to a
> different state, the triggered action should be "locked", so it can't be
> accessed again, unless it won't cause any damage.
>
> You would do this by giving the commandButton an ID, setting an f:param
> inside the button and getting this parameter (if you have a dynamic model
> and need to know which button has been clicked) back in the application via
> an ActionEvent, which is a parameter for an actionListener method.
>
> I had to do this for a system that locks datasets and prevents other users
> from editing. A user should only be able to edit one record at a time. If
> the user acts quickly and clicks several buttons on the page, that would
> open many open records. So what I did, is catch the ID and the param, unlock
> the records he clicked before and open only the last one for editing. If
> your problem is similar in some way, this might be a solution. A dirty one,
> I admit, but it works.
>
>
> Andreas
>
>
> Emily Gu wrote:
>
> Hi,
>
> Would you please let me know how do you know it is clicked the same
> button so that you can provent the next click by doing this?
>
> Thanks,
> Emily
>
>
> On 1/25/06, Hansjörg Meuschel <hj...@gmx.de> wrote:
> >
> > Hi Steffen,
> > thanks for this great information, the filter works perfectly and solved
> > one of my biggest problems with my application !!!!!
> >
> > Steffen Hankiewicz wrote:
> >
> > >Hi Hansjörg,
> > >
> > >
> > >
> > >>how can I prevent impatient users of my webapp to perform actions
> > twice
> > >>by clicking serveral times on the commandbuttons ??
> > >>
> > >>
> > >
> > >I am using a servlet filter which works great here. Maybe you want to
> > >give it a try:
> > >
> > > http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
> > >
> > >HTH,
> > >
> > >Steffen Hankiewicz
> > >
> > >
> > >
> > >
> >
> >
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Andreas Zeller - zit-systems <an...@zit-systems.de>.
Hey Emily,
If your Button causes your application to fail in some way, you could
catch that kind of bad user interaction by identifying the clicked
button via the component id (which is unique for each component on your
page).
This is kind of a "dirty" solution, but if the application switches to a
different state, the triggered action should be "locked", so it can't be
accessed again, unless it won't cause any damage.
You would do this by giving the commandButton an ID, setting an f:param
inside the button and getting this parameter (if you have a dynamic
model and need to know which button has been clicked) back in the
application via an ActionEvent, which is a parameter for an
actionListener method.
I had to do this for a system that locks datasets and prevents other
users from editing. A user should only be able to edit one record at a
time. If the user acts quickly and clicks several buttons on the page,
that would open many open records. So what I did, is catch the ID and
the param, unlock the records he clicked before and open only the last
one for editing. If your problem is similar in some way, this might be a
solution. A dirty one, I admit, but it works.
Andreas
Emily Gu wrote:
> Hi,
>
> Would you please let me know how do you know it is clicked the same
> button so that you can provent the next click by doing this?
>
> Thanks,
> Emily
>
>
> On 1/25/06, *Hansjörg Meuschel* <hjmeu@gmx.de <ma...@gmx.de>>
> wrote:
>
> Hi Steffen,
> thanks for this great information, the filter works perfectly and
> solved
> one of my biggest problems with my application !!!!!
>
> Steffen Hankiewicz wrote:
>
> >Hi Hansjörg,
> >
> >
> >
> >>how can I prevent impatient users of my webapp to perform
> actions twice
> >>by clicking serveral times on the commandbuttons ??
> >>
> >>
> >
> >I am using a servlet filter which works great here. Maybe you
> want to
> >give it a try:
> >
> >
> http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
> >
> >HTH,
> >
> >Steffen Hankiewicz
> >
> >
> >
> >
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Emily Gu <e2...@gmail.com>.
Hi,
Would you please let me know how do you know it is clicked the same button
so that you can provent the next click by doing this?
Thanks,
Emily
On 1/25/06, Hansjörg Meuschel <hj...@gmx.de> wrote:
>
> Hi Steffen,
> thanks for this great information, the filter works perfectly and solved
> one of my biggest problems with my application !!!!!
>
> Steffen Hankiewicz wrote:
>
> >Hi Hansjörg,
> >
> >
> >
> >>how can I prevent impatient users of my webapp to perform actions twice
> >>by clicking serveral times on the commandbuttons ??
> >>
> >>
> >
> >I am using a servlet filter which works great here. Maybe you want to
> >give it a try:
> >
> >http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
> >
> >HTH,
> >
> >Steffen Hankiewicz
> >
> >
> >
> >
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Hansjörg Meuschel <hj...@gmx.de>.
Hi Steffen,
thanks for this great information, the filter works perfectly and solved
one of my biggest problems with my application !!!!!
Steffen Hankiewicz wrote:
>Hi Hansjörg,
>
>
>
>>how can I prevent impatient users of my webapp to perform actions twice
>>by clicking serveral times on the commandbuttons ??
>>
>>
>
>I am using a servlet filter which works great here. Maybe you want to
>give it a try:
>
>http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
>
>HTH,
>
>Steffen Hankiewicz
>
>
>
>
Re: how do I prevent nervous users starting actions more than once???
Posted by Steffen Hankiewicz <ha...@sub.uni-goettingen.de>.
Hi Hansjörg,
> how can I prevent impatient users of my webapp to perform actions twice
> by clicking serveral times on the commandbuttons ??
I am using a servlet filter which works great here. Maybe you want to
give it a try:
http://www.onjava.com/pub/a/onjava/2004/03/24/loadcontrol.html?page=1
HTH,
Steffen Hankiewicz