wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Grigorov <mgrigo...@apache.org>
Subject Re: How to stop event propagation?
Date Thu, 09 Jul 2015 08:15:39 GMT
Oh, right!
Sorry! It was too early for me it seems.

The this should work.
You can simplify it a bit:

AjaxCallListener myAjaxCallListener = new AjaxCallListener();
myAjaxCallListener.onPrecondition("return Wicket.Event.keyCode(attrs.event)
=== 13");

No need to set the event propagation because STOP is the default:
https://github.com/apache/wicket/blob/wicket-6.x/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java#L85
But keep it there because this is changed in Wicket 7.x
...

Put a breakpoint at
https://github.com/apache/wicket/blob/wicket-6.x/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js#L1916
and see what happens

Martin Grigorov
Freelancer. Available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Jul 9, 2015 at 11:05 AM, gump lee <zeno.new@gmail.com> wrote:

> I use the following code to register the AjaxCallListener
>
> @Override
> protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
>
> AjaxCallListener myAjaxCallListener = new AjaxCallListener() {
> @Override
> public CharSequence getPrecondition(Component component) {
> String script = "var keycode = Wicket.Event.keyCode(attrs.event);"
> + "if (keycode == 13) {"
> + "    return true;"
> + "} else {" + "    return false;}";
>
> return script;
> }
> };
> * attributes.getAjaxCallListeners().add(myAjaxCallListener);*
> attributes.setEventPropagation(EventPropagation.STOP);
> super.updateAjaxAttributes(attributes);
> }
>
> or would you show me the correct way to register the AjaxCallListener?
>
> On Thu, Jul 9, 2015 at 2:45 PM, Martin Grigorov <mgrigorov@apache.org>
> wrote:
>
> > There is no attachment in both of your mails.
> > I don't see this line in your first message.
> >
> > Martin Grigorov
> > Freelancer. Available for hire!
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Thu, Jul 9, 2015 at 9:42 AM, gump lee <zeno.new@gmail.com> wrote:
> >
> > > Thanks,
> > >
> > > Actually I did it. refer to my attached code, I register my
> > > AjaxcallListener. Did I register the AjaxCallListener correctly?
> > >
> > > On Thu, Jul 9, 2015 at 2:23 PM, Martin Grigorov <mgrigorov@apache.org>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > You need to register the AjaxCallListener:
> > > > attributes.getAjaxCallListeners().add(myAjaxCallListener)
> > > >
> > > > Martin Grigorov
> > > > Freelancer. Available for hire!
> > > > Wicket Training and Consulting
> > > > https://twitter.com/mtgrigorov
> > > >
> > > > On Thu, Jul 9, 2015 at 5:11 AM, gump lee <zeno.new@gmail.com> wrote:
> > > >
> > > > > Hello All,
> > > > >
> > > > > I am using Wicket 6.19. I added a
> > > > > AjaxFormComponentUpdatingBehavior("keypress")
> > > > > to a textfield so that when press any key will trigger my
> application
> > > to
> > > > > update something. I want this only happen when user press 'Enter'
> > key.
> > > so
> > > > > that I override the method updateAjaxAttributes in the
> > > > > AjaxFormComponentUpdatingBehavior
> > > > >
> > > > > @Override
> > > > > protected void updateAjaxAttributes(AjaxRequestAttributes
> > attributes) {
> > > > > super.updateAjaxAttributes(attributes);
> > > > > AjaxCallListener myAjaxCallListener = new AjaxCallListener() {
> > > > > @Override
> > > > > public CharSequence getPrecondition(Component component) {
> > > > > String script = "var keycode = Wicket.Event.keyCode(attrs.event);"
> > > > > + "if (keycode == 13) {"
> > > > > + "    return true;"
> > > > > + "} else {" + "    return false;}";
> > > > >
> > > > > return script;
> > > > > }
> > > > > };
> > > > > attributes.getAjaxCallListeners().add(myAjaxCallListener);
> > > > > attributes.setEventPropagation(EventPropagation.STOP);
> > > > > }
> > > > >
> > > > > However, after the ajax call, the form submit also triggered. Does
> > > anyone
> > > > > know the correct way to stop this form submit?
> > > > >
> > > > >
> > > > > Thanks and best regards,
> > > > > Gump
> > > > >
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message