You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Matthijs Wensveen <m....@func.nl> on 2008/02/06 13:37:02 UTC

Block second click

Hello,

I have a Link (not Ajax) on a component that does some heavyweight 
processing in onClick. During this processing I want to block other 
clicks from the same user. Is there a generic way to block multiple 
requests on the same link? I would prefer a solution without Ajax / 
JavaScript, but if that's impossible then that's okay.

Thanks,
Matthijs

-- 
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.

Matthijs Wensveen wrote:
> Hello,
>
> I have a Link (not Ajax) on a component that does some heavyweight 
> processing in onClick. During this processing I want to block other 
> clicks from the same user. Is there a generic way to block multiple 
> requests on the same link?
> I would prefer a solution without Ajax / JavaScript, but if that's 
> impossible then that's okay.
>
I dont think thats possible, maybe with some meta refresh... Otherwise 
popup a layer with a higher z-index and that will block all until page 
reload, for minimal js.. Or use one of the ajax indicating stuff..
> Thanks,
> Matthijs
>

-- 
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Igor Vaynberg <ig...@gmail.com>.
there is a mask component in wicketstuff-minis. you can write a call
decorator that will bring up the mask that will cover the whole screen
and prevent the user from clicking.

-igor


On Feb 6, 2008 4:37 AM, Matthijs Wensveen <m....@func.nl> wrote:
> Hello,
>
> I have a Link (not Ajax) on a component that does some heavyweight
> processing in onClick. During this processing I want to block other
> clicks from the same user. Is there a generic way to block multiple
> requests on the same link? I would prefer a solution without Ajax /
> JavaScript, but if that's impossible then that's okay.
>
> Thanks,
> Matthijs
>
> --
> Matthijs Wensveen
> Func. Internet Integration
> W http://www.func.nl
> T +31 20 4230000
> F +31 20 4223500
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Johan Compagner <jc...@gmail.com>.
those are serverside solutions
and thats not the problem here. They are already one after each other in
wicket (in one session)

johan



On Feb 11, 2008 11:37 AM, C. Bergström <cb...@netsyncro.com> wrote:

> Haven't read the entire thread, but based on a best guess.. Would this
> be helpful in some way?
>
>
> http://blogs.webtide.com/gregw/2006/10/18/1161127500000.html
>
> Throttling filter
> http://jetty.mortbay.org/xref/org/mortbay/servlet/ThrottlingFilter.html
>
>
> ./C
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
t

Re: Block second click

Posted by "C. Bergström" <cb...@netsyncro.com>.
Haven't read the entire thread, but based on a best guess.. Would this
be helpful in some way?


http://blogs.webtide.com/gregw/2006/10/18/1161127500000.html

Throttling filter
http://jetty.mortbay.org/xref/org/mortbay/servlet/ThrottlingFilter.html


./C


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Matthijs Wensveen <m....@func.nl>.
Ah, thanks for clearing that up.
In my case the processing has to be done once and only once, so 
setEnabled(true) need not be called. After successful processing 
setResponsePage(..) is called. So this should still work just for me, 
right? I'll try tomorrow. If that doesn't work, I'll look at JS solutions.

Thanks for all the help,
Matthijs

Johan Compagner wrote:
> this code doesn't work at all.
>
> the onclick method isn't called at the same time by 2 request (2 link
> clicks)
> They are synchronized by wicket itself.
>
> So what happens with the code below is that the first request sets the
> enabled to false
> then does the processing, then wicket blocks the second request in the mean
> time
> then the processing is finished, the link is enabled again. That request
> does its processing rendering
> after it is finished wicket will release the second request and that does
> exactly the same thing as the first.
>
> So the heavy stuff is always done twice, but it is done twice in sequence
> If you don't want that then the only solution is to block the second click
> in the browser using javascript magic.
>
> johan
>
>
> On Feb 6, 2008 5:12 PM, Timo Rantalaiho <Ti...@ri.fi> wrote:
>
>   
>> On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
>>     
>>> I have a Link (not Ajax) on a component that does some heavyweight
>>> processing in onClick. During this processing I want to block other
>>> clicks from the same user. Is there a generic way to block multiple
>>> requests on the same link? I would prefer a solution without Ajax /
>>> JavaScript, but if that's impossible then that's okay.
>>>       
>> Components are stateful, so maybe you could just keep the
>> state in your Link?
>>
>>  @Override onClick() {
>>      if (!isEnabled()) {
>>          return;  // this shouldnt happen though?
>>      }
>>      try {
>>          setEnabled(false);
>>          doSomeHeavyWeightProcessing();
>>      } finally {
>>          setEnabled(true);
>>      }
>>  }
>>
>> This creates a little race condition but if you can produce
>> it you could try using a real lock mechanism.
>>
>> Best wishes,
>> Timo
>>
>> --
>> Timo Rantalaiho
>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Mon, 11 Feb 2008, Johan Compagner wrote:
> this code doesn't work at all.

Ah, thanks for clearing that out :)

The nth rule of the Internets: to find a working solution,
post a wrong solution.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Johan Compagner <jc...@gmail.com>.
this code doesn't work at all.

the onclick method isn't called at the same time by 2 request (2 link
clicks)
They are synchronized by wicket itself.

So what happens with the code below is that the first request sets the
enabled to false
then does the processing, then wicket blocks the second request in the mean
time
then the processing is finished, the link is enabled again. That request
does its processing rendering
after it is finished wicket will release the second request and that does
exactly the same thing as the first.

So the heavy stuff is always done twice, but it is done twice in sequence
If you don't want that then the only solution is to block the second click
in the browser using javascript magic.

johan


On Feb 6, 2008 5:12 PM, Timo Rantalaiho <Ti...@ri.fi> wrote:

> On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
> > I have a Link (not Ajax) on a component that does some heavyweight
> > processing in onClick. During this processing I want to block other
> > clicks from the same user. Is there a generic way to block multiple
> > requests on the same link? I would prefer a solution without Ajax /
> > JavaScript, but if that's impossible then that's okay.
>
> Components are stateful, so maybe you could just keep the
> state in your Link?
>
>  @Override onClick() {
>      if (!isEnabled()) {
>          return;  // this shouldnt happen though?
>      }
>      try {
>          setEnabled(false);
>          doSomeHeavyWeightProcessing();
>      } finally {
>          setEnabled(true);
>      }
>  }
>
> This creates a little race condition but if you can produce
> it you could try using a real lock mechanism.
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Block second click

Posted by Matthijs Wensveen <m....@func.nl>.
Martijn Dashorst wrote:
> On 2/7/08, Matthijs Wensveen <m....@func.nl> wrote:
>   
>> The if(!isEnabled()) will happen though, because the link is not really
>> disabled on the client side, but it does prevent
>> doSomeHeavyWeightProcessing to be called the second time which is what I
>> need.
>>     
>
> The problem is that the href of the link points to the old version of
> the page, and that has the link still enabled.
>
> Martijn
>   

Okay, so that won't prevent doSomeHWProc. Would a private member 
variable do the trick? Following the same logic, I'd say no.
Any ideas as to how this could be done? A session scope variable 
probably, but that would be *very* ugly. Is there a scope beyond the 
versioned page but smaller than the session? Page-global or something 
like that?

Hmm... does the version of the page that the link points to really have 
the link enabled? Isn't that version the same version that is doing the 
processing? And before that, setEnabled(false) is called... The same 
goes for the private member variable trick. I'm wondering...

Thanks,
Matthijs.
>   
>> What are the pros / cons of (ab)using setEnabled for this instead of
>> just a member variable)?
>>
>> Thanks,
>> Matthijs
>>
>> Timo Rantalaiho wrote:
>>     
>>> On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
>>>
>>>       
>>>> I have a Link (not Ajax) on a component that does some heavyweight
>>>> processing in onClick. During this processing I want to block other
>>>> clicks from the same user. Is there a generic way to block multiple
>>>> requests on the same link? I would prefer a solution without Ajax /
>>>> JavaScript, but if that's impossible then that's okay.
>>>>
>>>>         
>>> Components are stateful, so maybe you could just keep the
>>> state in your Link?
>>>
>>>   @Override onClick() {
>>>       if (!isEnabled()) {
>>>           return;  // this shouldnt happen though?
>>>       }
>>>       try {
>>>           setEnabled(false);
>>>           doSomeHeavyWeightProcessing();
>>>       } finally {
>>>           setEnabled(true);
>>>       }
>>>   }
>>>
>>> This creates a little race condition but if you can produce
>>> it you could try using a real lock mechanism.
>>>
>>> Best wishes,
>>> Timo
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Martijn Dashorst <ma...@gmail.com>.
On 2/7/08, Matthijs Wensveen <m....@func.nl> wrote:
> The if(!isEnabled()) will happen though, because the link is not really
> disabled on the client side, but it does prevent
> doSomeHeavyWeightProcessing to be called the second time which is what I
> need.

The problem is that the href of the link points to the old version of
the page, and that has the link still enabled.

Martijn

> What are the pros / cons of (ab)using setEnabled for this instead of
> just a member variable)?
>
> Thanks,
> Matthijs
>
> Timo Rantalaiho wrote:
> > On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
> >
> >> I have a Link (not Ajax) on a component that does some heavyweight
> >> processing in onClick. During this processing I want to block other
> >> clicks from the same user. Is there a generic way to block multiple
> >> requests on the same link? I would prefer a solution without Ajax /
> >> JavaScript, but if that's impossible then that's okay.
> >>
> >
> > Components are stateful, so maybe you could just keep the
> > state in your Link?
> >
> >   @Override onClick() {
> >       if (!isEnabled()) {
> >           return;  // this shouldnt happen though?
> >       }
> >       try {
> >           setEnabled(false);
> >           doSomeHeavyWeightProcessing();
> >       } finally {
> >           setEnabled(true);
> >       }
> >   }
> >
> > This creates a little race condition but if you can produce
> > it you could try using a real lock mechanism.
> >
> > Best wishes,
> > Timo
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.1 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.1

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Matthijs Wensveen <m....@func.nl>.
Hi,

The if(!isEnabled()) will happen though, because the link is not really 
disabled on the client side, but it does prevent 
doSomeHeavyWeightProcessing to be called the second time which is what I 
need.
What are the pros / cons of (ab)using setEnabled for this instead of 
just a member variable)?

Thanks,
Matthijs

Timo Rantalaiho wrote:
> On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
>   
>> I have a Link (not Ajax) on a component that does some heavyweight 
>> processing in onClick. During this processing I want to block other 
>> clicks from the same user. Is there a generic way to block multiple 
>> requests on the same link? I would prefer a solution without Ajax / 
>> JavaScript, but if that's impossible then that's okay.
>>     
>
> Components are stateful, so maybe you could just keep the
> state in your Link?
>
>   @Override onClick() {
>       if (!isEnabled()) {
>           return;  // this shouldnt happen though?
>       }
>       try {
>           setEnabled(false);
>           doSomeHeavyWeightProcessing();
>       } finally {
>           setEnabled(true);
>       }
>   }
>
> This creates a little race condition but if you can produce 
> it you could try using a real lock mechanism.
>
> Best wishes,
> Timo
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Block second click

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Wed, 06 Feb 2008, Matthijs Wensveen wrote:
> I have a Link (not Ajax) on a component that does some heavyweight 
> processing in onClick. During this processing I want to block other 
> clicks from the same user. Is there a generic way to block multiple 
> requests on the same link? I would prefer a solution without Ajax / 
> JavaScript, but if that's impossible then that's okay.

Components are stateful, so maybe you could just keep the
state in your Link?

  @Override onClick() {
      if (!isEnabled()) {
          return;  // this shouldnt happen though?
      }
      try {
          setEnabled(false);
          doSomeHeavyWeightProcessing();
      } finally {
          setEnabled(true);
      }
  }

This creates a little race condition but if you can produce 
it you could try using a real lock mechanism.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org