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 <[EMAIL PROTECTED]> 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 < [EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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
>
>
>
>

