You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by grazia <Gr...@gmail.com> on 2012/03/09 15:03:04 UTC
How to include a link to a css file not in classpath (not in
WEB-INF)
Still not clear what I did wrong.
With wicket 1.4 my code was:
public final class PageHeaderComponent extends WebComponent {
public PageHeaderComponent(final String id, final String
changeDestination) {
super(id);
add(CSSPackageResource.getHeaderContribution("/css/header.css"));
}
(...)
}
and it created what I needed
<link rel="stylesheet" type="text/css" href="/css/header.css" />
Now with wicket 1.5, my code is:
public final class PageHeaderComponent extends WebComponent {
public PageHeaderComponent(final String id, final String
changeDestination) {
super(id);
add(new Behavior() {
private final ResourceReference headerCss = new
PackageResourceReference("/css/header.css");
@Override
public void renderHead(Component component, IHeaderResponse
response) {
response.renderCSSReference(headerCss);
}
});
}
(...)
}
and it creates:
<link rel="stylesheet" type="text/css"
href="wicket/resource/org.apache.wicket.Application/css/header.css" />
The warning being logged is:
WARNING: Asked to auto-create a ResourceReference, but
ResourceReferenceRegistry
.createDefaultResourceReference() return null. [scope:
org.apache.wicket.Application; name: css/header.css; locale: null; style:
null; variation: null]
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-include-a-link-to-a-css-file-not-in-classpath-not-in-WEB-INF-tp4459528p4459528.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 include a link to a css file not in classpath (not in
WEB-INF)
Posted by grazia <Gr...@gmail.com>.
Hi Simon,
thanks a lot. It works.
I am new to wicket as well.
I was going to try this
http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/, but the
solution you have requires fewer lines of code.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-include-a-link-to-a-css-file-not-in-classpath-not-in-WEB-INF-tp4459528p4465994.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 include a link to a css file not in classpath (not in
WEB-INF)
Posted by sb <si...@gmail.com>.
Hi,
I'm pretty new to Wicket but I had a similar problem and did the following:
In your Application subclass
@Override
public void init() {
...
getSharedResources().add("cssheader", new
ContextRelativeResource("/css/header.css"));
...
}
then in your component // behavior or whatever use a SharedResourceReference
with the key you added the ContextRelativeResource with.
e.g.
@Override
public void renderHead(Component component, IHeaderResponse response) {
response.renderCSSReference(new SharedResource("cssheader"));
}
in the rendered page your resource won't be rendered as "/css/header.css"
but as something like :
<link rel="stylesheet" type="text/css"
href="../resource/org.apache.wicket.Application/header-ver-1331389482368" />
But it will point to the correct file.
Like I said I'm just beginning to use the Wicket framework so if someone
else knows a better way or my way is flawed please correct me.
Cheers
Simon
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-include-a-link-to-a-css-file-not-in-classpath-not-in-WEB-INF-tp4459528p4462155.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 include a link to a css file not in classpath (not in WEB-INF)
Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Mar 9, 2012 at 4:03 PM, grazia <Gr...@gmail.com> wrote:
> Still not clear what I did wrong.
> With wicket 1.4 my code was:
>
> public final class PageHeaderComponent extends WebComponent {
>
> public PageHeaderComponent(final String id, final String
> changeDestination) {
> super(id);
> add(CSSPackageResource.getHeaderContribution("/css/header.css"));
> }
> (...)
> }
>
> and it created what I needed
> <link rel="stylesheet" type="text/css" href="/css/header.css" />
>
> Now with wicket 1.5, my code is:
>
> public final class PageHeaderComponent extends WebComponent {
>
No need of Behavior, no need of PackageResourceReference.
public PageHeaderComponent(final String id, final String
changeDestination) {
super(id);
@Override
public void renderHead(Component component, IHeaderResponse response) {
response.renderCSSReference("/css/header.css");
}
});
> }
> (...)
> }
>
> and it creates:
> <link rel="stylesheet" type="text/css"
> href="wicket/resource/org.apache.wicket.Application/css/header.css" />
>
> The warning being logged is:
>
> WARNING: Asked to auto-create a ResourceReference, but
> ResourceReferenceRegistry
> .createDefaultResourceReference() return null. [scope:
> org.apache.wicket.Application; name: css/header.css; locale: null; style:
> null; variation: null]
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-include-a-link-to-a-css-file-not-in-classpath-not-in-WEB-INF-tp4459528p4459528.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
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org