You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by brushmate <br...@gmail.com> on 2014/09/09 12:20:40 UTC

How to register a global resource with dependencies?

Hi,I want to register a JS file globally, but it depends on jQuery. The user
guide says that rsources can be registered with
getSharedResources().add(String name, IResource resource). But since it
takes an IResource, I can not declare the dependencies with overriding
getDependencies() like I would do with a ResourceReference. So how can I
register a global JavaScript resource that depends on jQuery?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: How to register a global resource with dependencies?

Posted by Tobias Soloschenko <to...@googlemail.com>.
You can get the JQueryResourceReference used by Wicket like this:

getJavaScriptLibrarySettings().getJQueryReference()

kind regards

Tobias

2014-09-09 12:20 GMT+02:00 brushmate <br...@gmail.com>:

> Hi,I want to register a JS file globally, but it depends on jQuery. The
> user
> guide says that rsources can be registered with
> getSharedResources().add(String name, IResource resource). But since it
> takes an IResource, I can not declare the dependencies with overriding
> getDependencies() like I would do with a ResourceReference. So how can I
> register a global JavaScript resource that depends on jQuery?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to register a global resource with dependencies?

Posted by Tobias Soloschenko <to...@googlemail.com>.
You could use resource bundles, define all ResourceReferences within the
bundle and within each ResourceReference their dependencies. If you would
use any resourcereference within a renderHead method, all dependencies and
resources would placed at the right position and you would save some
requests.

2014-09-09 12:35 GMT+02:00 brushmate <br...@gmail.com>:

> Thanks for your answer. So everytime I want to reference a resource, I have
> to declare its dependencies?
>
> I want to register it globally, because I can use it on different pages
> then
> and if the path to the resource changes in the future, I only need to
> update
> it at one place.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403p4667407.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to register a global resource with dependencies?

Posted by Martin Grigorov <mg...@apache.org>.
This is OK.
Override Component#renderHead() or Behavior#renderHead() and list all
references that are needed.
You can also
use org.apache.wicket.Application#getHeaderContributorListeners().add(new
IHeaderContributor() { #renderHead() {...} }) to define which header items
should be contributed for every request.

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


On Tue, Sep 9, 2014 at 1:47 PM, brushmate <br...@gmail.com> wrote:

> Okay, then I have another question:
>
> Where do I have to define the references. Until now, I always defined them
> in the component that needs them.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403p4667411.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to register a global resource with dependencies?

Posted by brushmate <br...@gmail.com>.
Okay, then I have another question:

Where do I have to define the references. Until now, I always defined them
in the component that needs them.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403p4667411.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: How to register a global resource with dependencies?

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, Sep 9, 2014 at 1:35 PM, brushmate <br...@gmail.com> wrote:

> Thanks for your answer. So everytime I want to reference a resource, I have
> to declare its dependencies?
>
> I want to register it globally, because I can use it on different pages
> then
> and if the path to the resource changes in the future, I only need to
> update
> it at one place.
>

The same is valid for any other (non-shared) resource reference.
Just create a PackageResourceReference (e.g. Css or JS) and define the
scope class and the relative path. Or UrlResourceReference with the Url.
Define the dependencies.
Later if you need to change the scope/relativePath/url just do it. All
users of the reference will have the update for free.


>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403p4667407.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to register a global resource with dependencies?

Posted by brushmate <br...@gmail.com>.
Thanks for your answer. So everytime I want to reference a resource, I have
to declare its dependencies?

I want to register it globally, because I can use it on different pages then
and if the path to the resource changes in the future, I only need to update
it at one place.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403p4667407.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: How to register a global resource with dependencies?

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

You register the IResource with getSharedResources().add(String name,
IResource resource) but later you need to reference it with
SharedResourceReference(name) to be able to use it. You can override
SharedResourceReference's
getDependencies() to declare the JQuery dependency.

Why do you need to use shared resources at all ?
What benefit do you see ?

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


On Tue, Sep 9, 2014 at 1:20 PM, brushmate <br...@gmail.com> wrote:

> Hi,I want to register a JS file globally, but it depends on jQuery. The
> user
> guide says that rsources can be registered with
> getSharedResources().add(String name, IResource resource). But since it
> takes an IResource, I can not declare the dependencies with overriding
> getDependencies() like I would do with a ResourceReference. So how can I
> register a global JavaScript resource that depends on jQuery?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/How-to-register-a-global-resource-with-dependencies-tp4667403.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>