Have you tried turning the <link> tag into a dynamic WebMarkupContainer and
then switching its href attribute's value via an AttributeModifier?
HTML:
<html wicket:id="htmlTag">
<head>
<link wicket:id="cssHeadLink"> rel="stylesheet" type="text/css"
href="css/default-styles.css">
</head>
<body>
<wicket:child/>
</body>
</html>
Java:
public BasePage() {
htmlTag = new TransparentWebMarkupContainer("htmlTag");
htmlTag.add( new AttributeModifier("lang", new
Model<String>(getUserLocale().getLanguage())) );
add(htmlTag);
cssHeadLink = new WebMarkupContainer("cssHeadLink");
cssHeadLink.add( new AttributeModifier("href", new
Model<String>(getSkinStyleSheet())) );
htmlTag.add(cssHeadLink);
}
Then have getSkinStyleSheet() return the name of the CSS file or use any other
kind of IModel.
Notice the above example also shows the use of the
TransparentWebMarkupContainer used to change the HTML document's language in a
similar manner only it will not be part of the component path for pages that
extend BasePage. Here, getUserLocale() returns the Locale of the logged-in user
whose ID is stored the Session.
~ Thank you,
Paul Bors | Software Engineer | Knoa Software | 5 Union Square West, New York ,
NY 10003 | O: 212-807-9608 | www.knoa.com
-----Original Message-----
From: Pierre Goupil [mailto:[email protected]]
Sent: Thursday, July 19, 2012 2:57 PM
To: [email protected]
Subject: [1.5] [6.0] dynamically named CSS, JS & images resources
Good evening,
I'd like to contribute CSSs & JSs to my <head> for which names I don't know.
More precisely, I'd like to be able to download a .zip, unzip it and contribute
its CSS & JS content to the <head>, plus being able to display the images of
the zip thanks to the links in the CSS.
Regarding the downloading and unzipping steps, it's easy. But for the header
contributions, I can't figure out how to do that since :
1) I don't know the names of the CSS & JS files before download
2) the CSS files link to the images using their regular names, but Wicket
appends characters of its own to their names.
What I'm trying to achieve is to be able to switch (at run-time) my app's theme
by downloading a new one on a themes website, like
http://www.freecsstemplates.org/
I use Wicket 1.5.7 but a solution for Wicket 6.0 is OK as well.
Any help will be much appreciated.
Regards,
Pierre Goupil
--
Le bonheur n'est pas une destination, mais une façon de voyager.
Papa d'une petite Lou-Ann depuis le 30 juin.