开发者

Wicket - <wicket:link> - How to put pages in different packages?

I have a web app, and it has a directory structure like:

/com/myproject/MyPage.java
/com/myproject/MyPage.html
/com/myproject/resources/styles.css
/com/myproject/resources/bg.png

In MyPage.html I have code like:

<wicket:link>
  <link rel="stylesheet" type="text/css" href="resources/styles.css"/>
</wicket:link>

The CSS file has references like url(bg.png). And all is good.

However, my app is now getting so big (I have about 15 pages so far), I don't want to put all the pages and HTML in one directory. However things like "styles.css" are referenced from all pages. So I would like to create various packages for various groups of pages, but still have "styles.css", and the images etc. that it references, existing only once in my source tree.

I would like to do something like:

  • Create e.g. /com/myproject/usermanagement/UserManagementStartPage.java
  • but still have /com/myproject/resources/styles.css (with the intention of sharing that between all pages)
  • The HTML still references the CSS with a <wicket:link>, e.g. href="../resources/styles.css"
  • Or 开发者_JS百科even better, have an absolute link to the css e.g. href="/com/myproject/resources/styles.css (that way when I move a page from one package to a deeper/shallower package, I don't have to change the number of ...)

Am I thinking along the right lines? How would you approach this problem?


You need something like:

<wicket:link>
  <link rel="stylesheet" type="text/css" href="$up$/resources/styles.css"/>
</wicket:link>

org.apache.wicket.settings.IResourceSettings.setParentFolderPlaceholder("$up$")

This way the url will look like /com/myproject/usermanagement/$up$/resources/styles.css and Wicket will resolve the parent folder for you.


Wicket handles CSS file links that are relative to the root of the web app. That way, it doesn't matter if you move a markup file one level higher or deeper. It is also possible to include style sheets from Java code, as explained in this article . Using markup inheritance, you can just add your style sheet to your base page and let your real pages inherit from it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜