You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dieter Tremel <tr...@tremel-computer.de> on 2015/10/07 10:12:51 UTC
Resolution of url() in ContextRelativeResourceReference
Hello list,
Using Bootstrap 3.3.5 I want to include the stylesheet, js and font
resources myself, not using wicket-bootstrap. To have a dependency to
wicket's jquery version I decided to move resource handling from html to
java and to use ContextRelativeResourceReference like this:
> ContextRelativeResourceReference bootstrapCSS = new ContextRelativeResourceReference("css/bootstrap.css");
> response.render(CssHeaderItem.forReference(bootstrapCSS));
> ...
When using gylphicons the icons are not rendered correctly, a 404 error
is given for the fonts and the log says
> 09:45:37.976 [http-nio-8084-exec-6] WARN o.a.w.r.r.ResourceReferenceRegistry - A ResourceReference wont be created for a resource with key [scope: org.apache.wicket.Application; name: fonts/glyphicons-halflings-regular.ttf; locale: null; style: null; variation: null] because it cannot be located.
The fonts are defined in bootstrap.css with paths relative to css folder
like this
> @font-face {
> font-family: 'Glyphicons Halflings';
>
> src: url('../fonts/glyphicons-halflings-regular.eot');
> src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
> }
Of course the fonts exist at /src/main/webapp/fonts (sibling of folder
css) and are in the war file at /fonts.
I tried to use
getResourceSettings().setCssCompressor(new CssUrlReplacer());
in my WebApplication#init but with no difference, the errors are still
there.
What is the correct way of resource handling at java side?
Thank You
Dieter Tremel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Dieter Tremel <tr...@tremel-computer.de>.
Now I understand. Thank You Martin.
Dieter
Am 08.10.2015 um 12:08 schrieb Martin Grigorov:
> Hi,
>
> I guess the problem is that you have a context path and the person who
> wrote the guide didn't have it.
> If there is no context path then "/style.css" and "style.css" would resolve
> to the same - the resource that is in the root of the app.
> If there is context path then the absolute url that the browser will use
> will be http://host:port/style.css instead of http://host:port
> /contextPath/style.css
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Thu, Oct 8, 2015 at 10:01 AM, Dieter Tremel <tr...@tremel-computer.de>
> wrote:
>
>> Am 08.10.2015 um 08:14 schrieb Dieter Tremel:
>>> With a JavaScriptHeaderItem the slash makes no difference, only with
>>> CssHeaderItem.
>>
>> Sorry, this is wrong, same problem with js.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
I guess the problem is that you have a context path and the person who
wrote the guide didn't have it.
If there is no context path then "/style.css" and "style.css" would resolve
to the same - the resource that is in the root of the app.
If there is context path then the absolute url that the browser will use
will be http://host:port/style.css instead of http://host:port
/contextPath/style.css
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Thu, Oct 8, 2015 at 10:01 AM, Dieter Tremel <tr...@tremel-computer.de>
wrote:
> Am 08.10.2015 um 08:14 schrieb Dieter Tremel:
> > With a JavaScriptHeaderItem the slash makes no difference, only with
> > CssHeaderItem.
>
> Sorry, this is wrong, same problem with js.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Dieter Tremel <tr...@tremel-computer.de>.
Am 08.10.2015 um 08:14 schrieb Dieter Tremel:
> With a JavaScriptHeaderItem the slash makes no difference, only with
> CssHeaderItem.
Sorry, this is wrong, same problem with js.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Dieter Tremel <tr...@tremel-computer.de>.
Hi Martin,
The url is (in DEVELOPMENT mode):
<link rel="stylesheet" type="text/css"
href="./wicket/resource/org.apache.wicket.Application/css/bootstrap-ver-1434463970000.css"
/>
At the moment I use a workaround by including the css by html and the js
by java code:
> ContextRelativeResourceReference bootstrapJavascript
> = new ContextRelativeResourceReference("js/bootstrap.js") {
> // use wicket's jquery lib for Bootstrap
> @Override
> public List<HeaderItem> getDependencies() {
> Application application = Application.get();
> ResourceReference jqueryRef = application.getJavaScriptLibrarySettings().
> getJQueryReference();
>
> return Arrays.asList(new HeaderItem[]{JavaScriptHeaderItem.forReference(jqueryRef)});
> }
> };
> response.render(JavaScriptHeaderItem.forReference(bootstrapJavascript));
This works.
After some investigations I think including css by
ContextRelativeResource is not widely used, I must be a quirky
developer, because I always try to use libs the exotic way ;-)
By the way there is another strange effect, perhaps a bug:
When I include css with a leading slash as described in Guide "16.5
Context-relative resources"
https://ci.apache.org/projects/wicket/guide/7.x/guide/resources.html#resources_5
it leads to a 404, without the slash it is found.
In a Quickstart with
> ContextRelativeResourceReference styles = new ContextRelativeResourceReference("/style.css");
leads to
> HTTP Status 404 - /Quickstart20151008/wicket/resource/org.apache.wicket.Application/style-ver-1444283523604.css
whereas
> ContextRelativeResourceReference styles = new ContextRelativeResourceReference("style.css");
is OK.
Strange because in ContextRelativeResource there is a demand for the
leading slash:
> public ContextRelativeResource(String pathRelativeToContextRoot)
> {
> Args.notNull(pathRelativeToContextRoot, "pathRelativeToContextRoot");
>
> // Make sure there is a leading '/'.
> if (!pathRelativeToContextRoot.startsWith("/"))
> {
> pathRelativeToContextRoot = "/" + pathRelativeToContextRoot;
> }
> this.path = pathRelativeToContextRoot;
> this.cachingEnabled = true;
> }
With a JavaScriptHeaderItem the slash makes no difference, only with
CssHeaderItem.
Dieter
Am 07.10.2015 um 21:41 schrieb Martin Grigorov:
> Hi,
>
> What is the generated url for the .css resource ?
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Oct 7, 2015 at 10:12 AM, Dieter Tremel <tr...@tremel-computer.de>
> wrote:
>
>> Hello list,
>>
>> Using Bootstrap 3.3.5 I want to include the stylesheet, js and font
>> resources myself, not using wicket-bootstrap. To have a dependency to
>> wicket's jquery version I decided to move resource handling from html to
>> java and to use ContextRelativeResourceReference like this:
>>
>>> ContextRelativeResourceReference bootstrapCSS = new
>> ContextRelativeResourceReference("css/bootstrap.css");
>>> response.render(CssHeaderItem.forReference(bootstrapCSS));
>>> ...
>>
>> When using gylphicons the icons are not rendered correctly, a 404 error
>> is given for the fonts and the log says
>>> 09:45:37.976 [http-nio-8084-exec-6] WARN
>> o.a.w.r.r.ResourceReferenceRegistry - A ResourceReference wont be created
>> for a resource with key [scope: org.apache.wicket.Application; name:
>> fonts/glyphicons-halflings-regular.ttf; locale: null; style: null;
>> variation: null] because it cannot be located.
>>
>> The fonts are defined in bootstrap.css with paths relative to css folder
>> like this
>>> @font-face {
>>> font-family: 'Glyphicons Halflings';
>>>
>>> src: url('../fonts/glyphicons-halflings-regular.eot');
>>> src: url('../fonts/glyphicons-halflings-regular.eot?#iefix')
>> format('embedded-opentype'),
>> url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
>> url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
>> url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
>> url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular')
>> format('svg');
>>> }
>>
>> Of course the fonts exist at /src/main/webapp/fonts (sibling of folder
>> css) and are in the war file at /fonts.
>>
>> I tried to use
>> getResourceSettings().setCssCompressor(new CssUrlReplacer());
>> in my WebApplication#init but with no difference, the errors are still
>> there.
>>
>> What is the correct way of resource handling at java side?
>>
>> Thank You
>> Dieter Tremel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
What is the generated url for the .css resource ?
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Wed, Oct 7, 2015 at 10:12 AM, Dieter Tremel <tr...@tremel-computer.de>
wrote:
> Hello list,
>
> Using Bootstrap 3.3.5 I want to include the stylesheet, js and font
> resources myself, not using wicket-bootstrap. To have a dependency to
> wicket's jquery version I decided to move resource handling from html to
> java and to use ContextRelativeResourceReference like this:
>
> > ContextRelativeResourceReference bootstrapCSS = new
> ContextRelativeResourceReference("css/bootstrap.css");
> > response.render(CssHeaderItem.forReference(bootstrapCSS));
> > ...
>
> When using gylphicons the icons are not rendered correctly, a 404 error
> is given for the fonts and the log says
> > 09:45:37.976 [http-nio-8084-exec-6] WARN
> o.a.w.r.r.ResourceReferenceRegistry - A ResourceReference wont be created
> for a resource with key [scope: org.apache.wicket.Application; name:
> fonts/glyphicons-halflings-regular.ttf; locale: null; style: null;
> variation: null] because it cannot be located.
>
> The fonts are defined in bootstrap.css with paths relative to css folder
> like this
> > @font-face {
> > font-family: 'Glyphicons Halflings';
> >
> > src: url('../fonts/glyphicons-halflings-regular.eot');
> > src: url('../fonts/glyphicons-halflings-regular.eot?#iefix')
> format('embedded-opentype'),
> url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'),
> url('../fonts/glyphicons-halflings-regular.woff') format('woff'),
> url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'),
> url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular')
> format('svg');
> > }
>
> Of course the fonts exist at /src/main/webapp/fonts (sibling of folder
> css) and are in the war file at /fonts.
>
> I tried to use
> getResourceSettings().setCssCompressor(new CssUrlReplacer());
> in my WebApplication#init but with no difference, the errors are still
> there.
>
> What is the correct way of resource handling at java side?
>
> Thank You
> Dieter Tremel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Resolution of url() in ContextRelativeResourceReference
Posted by Dieter Tremel <tr...@tremel-computer.de>.
For your information: I implemented a better solution with
http://www.webjars.org today.
> <dependency>
> <groupId>de.agilecoders.wicket.webjars</groupId>
> <artifactId>wicket-webjars</artifactId>
> <version>0.5.3</version>
> </dependency>
> <dependency>
> <groupId>org.webjars</groupId>
> <artifactId>bootstrap</artifactId>
> <version>3.3.5</version>
> </dependency>
If WebjarsCssResourceReference is used, the problem of the Glyphicons
fonts is solved.
Dieter
Am 07.10.2015 um 10:12 schrieb Dieter Tremel:
> Hello list,
>
> Using Bootstrap 3.3.5 I want to include the stylesheet, js and font
> resources myself, not using wicket-bootstrap. To have a dependency to
> wicket's jquery version I decided to move resource handling from html to
> java and to use ContextRelativeResourceReference like this:
>
>> ContextRelativeResourceReference bootstrapCSS = new ContextRelativeResourceReference("css/bootstrap.css");
>> response.render(CssHeaderItem.forReference(bootstrapCSS));
>> ...
>
> When using gylphicons the icons are not rendered correctly, a 404 error
> is given for the fonts and the log says
>> 09:45:37.976 [http-nio-8084-exec-6] WARN o.a.w.r.r.ResourceReferenceRegistry - A ResourceReference wont be created for a resource with key [scope: org.apache.wicket.Application; name: fonts/glyphicons-halflings-regular.ttf; locale: null; style: null; variation: null] because it cannot be located.
>
> The fonts are defined in bootstrap.css with paths relative to css folder
> like this
>> @font-face {
>> font-family: 'Glyphicons Halflings';
>>
>> src: url('../fonts/glyphicons-halflings-regular.eot');
>> src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
>> }
>
> Of course the fonts exist at /src/main/webapp/fonts (sibling of folder
> css) and are in the war file at /fonts.
>
> I tried to use
> getResourceSettings().setCssCompressor(new CssUrlReplacer());
> in my WebApplication#init but with no difference, the errors are still
> there.
>
> What is the correct way of resource handling at java side?
>
> Thank You
> Dieter Tremel
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org