jordeu
jordeu

Reputation: 6821

CSS theme system in Wicket

I'm developing a Wicket 1.5 web application with many different components, and I'm interested to let the user choose between different themes (that means change the CSS styles of some components). So in some way I'll associate the chosen theme with the user session.

My question is, which is the best way to do this in Wicket?

Right now my components look like this:

public class SingleLayout extends Panel {

    public static final CssResourceReference CSS = new CssResourceReference(SingleLayout.class, "SingleLayout.css");

    public SingleLayout(...) {
        super(...);
    }

    protected CssResourceReference getCssResourceReference() {
        return CSS;
    }

    @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);
        response.renderCSSReference(getCssResourceReference());
    }

}

My ideal solution 'theme system' would:

Upvotes: 1

Views: 841

Answers (1)

bert
bert

Reputation: 7696

I have not done this myself, but I would recomend to have a look at the Session in Wicket. In the Javadoc, it explains the resource loading. Part of the search allgorithm is the Style, which is obtained from the users session.

Idea behind it, that you provide provide a css for each style (what you call a theme). The fallback to the standart theme isinluded.

Hope that helps. Bert

Upvotes: 5

Related Questions