Quantcast

Log a warning when there are several ajax event behaviors on the same event

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Log a warning when there are several ajax event behaviors on the same event

Martin Grigorov-4
Hi,

What do you think about this additional code in
AjaxEventBehavior#onComponentTag() (Wicket 1.5) :

@@ -108,6 +112,20 @@ public abstract class AjaxEventBehavior extends
AbstractDefaultAjaxBehavior
                Component myComponent = getComponent();
                if (myComponent.isEnabledInHierarchy())
                {
+                       if (LOG.isWarnEnabled() &&
myComponent.getApplication().usesDevelopmentConfig())
+                       {
+                               String attribute = tag.getAttribute(event);
+                               if (Strings.isEmpty(attribute) == false)
+                               {
+                                       LOG.warn("{} assigned to {} is
overriding the previous value of the inline attribute. " +
+                                               "Maybe there are
several Ajax event behaviors on the same type assigned to this
component."
+                                               new Object[] {
+                                                       this, myComponent
+                                               }
+                                       );
+                               }
+                       }


The problem it tries to solve is that you can add several AEBs on the
same event type to a component and silently the last one wins.
This warning should tell the developer that something bad may happen

--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Log a warning when there are several ajax event behaviors on the same event

Igor Vaynberg-2
looks good to me

-igor

On Thu, Feb 23, 2012 at 6:01 AM, Martin Grigorov <[hidden email]> wrote:

> Hi,
>
> What do you think about this additional code in
> AjaxEventBehavior#onComponentTag() (Wicket 1.5) :
>
> @@ -108,6 +112,20 @@ public abstract class AjaxEventBehavior extends
> AbstractDefaultAjaxBehavior
>                Component myComponent = getComponent();
>                if (myComponent.isEnabledInHierarchy())
>                {
> +                       if (LOG.isWarnEnabled() &&
> myComponent.getApplication().usesDevelopmentConfig())
> +                       {
> +                               String attribute = tag.getAttribute(event);
> +                               if (Strings.isEmpty(attribute) == false)
> +                               {
> +                                       LOG.warn("{} assigned to {} is
> overriding the previous value of the inline attribute. " +
> +                                               "Maybe there are
> several Ajax event behaviors on the same type assigned to this
> component."
> +                                               new Object[] {
> +                                                       this, myComponent
> +                                               }
> +                                       );
> +                               }
> +                       }
>
>
> The problem it tries to solve is that you can add several AEBs on the
> same event type to a component and silently the last one wins.
> This warning should tell the developer that something bad may happen
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
Loading...