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 <[email protected]>
> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to