Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket & CSS resources

Tags:

java

css

wicket

I've been looking around and I can't find a dummy's guide to adding my own CSS to a Wicket website project. But before I start... I'm fairly new to proper java development, so when I say "Dummy's guide" I really mean it! Simple and clear explanations for me here are very much appreciated!

I started with this guide here (http://wicket.apache.org/start/quickstart.html) and have that running fine. Next up, I want to add my own CSS and start messing about with it. And I'm getting nowhere fast. Mainly because I haven't got a clue how to do this in java (I come from a C#/asp.net background).

Anyway, those that know Apache Wicket will know this already, but the source for the quick start creates your code in a place like follows project/src/main/java/com/xyz

What I presumed I could do was add a CSS folder here... so I created a sample CSS and I stuck it here like this:

project/src/main/java/com/xyz/css/conor.css

(containing something real simple like the following)

h2 {
    font-family: tahoma;
}

Then I removed the Wicket default css in my homepage.html and changed it to reference mine as follows:

<link rel="stylesheet" href="css/conor.css" type="text/css" />

But my page doesn't take any heed of the conor.css... Obviously I'm doing something wrong, but cannot find a step by step guide for a java dummy (aka me!).

I have read things like you need to install web tools for eclipse. I did have no idea what use this is to me or why it will instruct my pages to use the CSS.

Any help is very much appreciated!

like image 719
Conor Gallagher Avatar asked Apr 16 '12 21:04

Conor Gallagher


People also ask

What does wicket mean in slang?

A particularly awkward or difficult situation or circumstance. (Generally used with on. Refers to the pitch, i.e., wicket, used in the game of cricket and the difficulty of playing on one after it has been wetted with rain.) Primarily heard in UK, Australia.

What does getting a wicket mean?

The dismissal of a batsman is known as the taking of a wicket.

How many wickets are there in cricket?

The fielding team accumulates wickets against the batting team as this is their main goal. In most cases, the maximum number of wickets taken is ten. There are five main ways teams can collect a wicket. They are: being caught, bowled, run out, stumped, or leg before wicket.

What is the size of wicket?

Each set shall be 9 in/22.86 cm wide and shall consist of three wooden stumps with two wooden bails on top. See Appendix D. The tops of the stumps shall be 28 in/71.12 cm above the playing surface and shall be dome shaped except for the bail grooves.


1 Answers

While Wicket parses the markup and tries to come up with proper links, you have to help Wicket understand your markup.

In your case you try to link to a resource that is located in the Java class path. This is different from the web context root (located in src/main/webapp). The difference between class path resources and web context resources is that Wicket is responsible for and controls access to class path resources, and that your container (i.e. jetty, tomcat, glassfish, etc) is responsible for and controls access to web context resources.

For example, when a resource is under the purview of Wicket, we can do all kinds of things with it, such as variable substitution, compression, minification, aggregation. These things are part of Wicket.

Now to your problem at hand, since you didn't tell Wicket that the linked resources are under its control, Wicket assumes that you want the container to handle those. To mitigate this, you should add a <wicket:link> tag around your <link> tag(s).

<head>
    ...
    <wicket:link>
    <link rel="stylesheet" href="css/conor.css" type="text/css" />
    ...
    </wicket:link>
</head>

The <wicket:link> tags tell Wicket to look for the enclosed resources and try to resolve them on the Java class path.

like image 64
Martijn Dashorst Avatar answered Sep 24 '22 03:09

Martijn Dashorst