You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Matías Fernández <re...@gmail.com> on 2016/01/19 14:36:47 UTC

Problem with JS import order in page with only AbstractDefaultAjaxBehavior

Hello Wicket developers,

I have what I think is a issue but before report it I want to know if 
maybe this is a expected behavior. I have been searching in 
documentation and Internet about this but didn't found any behavior like 
this.

I'm using Wicket 7.1 and I build a page with only a 
AbstractDefaultAjaxBehavior's.

Also in this page I have some JQuery plug-ins which need to be loaded 
after JQuery is loaded. The problem is the JQuery from Wicket is loading 
after all the JS declared on wicket:head tag of the page, the problem is 
the plug-in doesn't work if the JS are loading in this order. The 
strange behavior is if I add a AjaxLink to the same page, the JS are 
loading ok and the page works but the AjaxLink isn't necessary.

I want to know why Wicket decide to do this in this two situations.

Thanks,
Matías.

Re: Problem with JS import order in page with only AbstractDefaultAjaxBehavior

Posted by Matías Fernández <re...@gmail.com>.
Thanks for your answer guys, I thought this was a issue, I'm going to 
try this.

Thanks a lot.

On 19/01/16 10:36, Matías Fernández wrote:
> Hello Wicket developers,
>
> I have what I think is a issue but before report it I want to know if 
> maybe this is a expected behavior. I have been searching in 
> documentation and Internet about this but didn't found any behavior 
> like this.
>
> I'm using Wicket 7.1 and I build a page with only a 
> AbstractDefaultAjaxBehavior's.
>
> Also in this page I have some JQuery plug-ins which need to be loaded 
> after JQuery is loaded. The problem is the JQuery from Wicket is 
> loading after all the JS declared on wicket:head tag of the page, the 
> problem is the plug-in doesn't work if the JS are loading in this 
> order. The strange behavior is if I add a AjaxLink to the same page, 
> the JS are loading ok and the page works but the AjaxLink isn't 
> necessary.
>
> I want to know why Wicket decide to do this in this two situations.
>
> Thanks,
> Matías.


Re: Problem with JS import order in page with only AbstractDefaultAjaxBehavior

Posted by Martin Grigorov <mg...@apache.org>.
Hi Matias,

As Sebastien suggested you need to tell Wicket that your jQuery plugins
depend on jQuery.
The easiest way is to create JavaScriptResourceReference for each of them
by extending JQueryPluginJavaScriptResourceReference.
By just putting the links in <wicket:head> there is not enough information
for Wicket to know that they require jQuery.
For more information please also check
http://wicketinaction.com/2012/07/wicket-6-resource-management/.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jan 19, 2016 at 3:06 PM, Sebastien <se...@gmail.com> wrote:

> Hi Matias,
>
> > Also in this page I have some JQuery plug-ins which need to be loaded
> after JQuery is loaded
>
> There is some way to control wicket:header priority, but it is probably
> better that you provide the ResourceReference, extending
> JQueryPluginResourceReference, so you are guaranteed it will be loaded
> *after* jquery
>
> Then you just have to render it like this:
>
> public void renderHead(Component component, IHeaderResponse response)
> {
>     ResourceReference reference = MyJQueryPluginResourceReference.get()
>
>     response.render(new
> PriorityHeaderItem(JavaScriptHeaderItem.forReference(reference)));
> }
>
> Hope this helps,
> Sebastien.
>

Re: Problem with JS import order in page with only AbstractDefaultAjaxBehavior

Posted by Sebastien <se...@gmail.com>.
Hi Matias,

> Also in this page I have some JQuery plug-ins which need to be loaded
after JQuery is loaded

There is some way to control wicket:header priority, but it is probably
better that you provide the ResourceReference, extending
JQueryPluginResourceReference, so you are guaranteed it will be loaded
*after* jquery

Then you just have to render it like this:

public void renderHead(Component component, IHeaderResponse response)
{
    ResourceReference reference = MyJQueryPluginResourceReference.get()

    response.render(new
PriorityHeaderItem(JavaScriptHeaderItem.forReference(reference)));
}

Hope this helps,
Sebastien.