7

Currently, I have an Application which consists of a BasePage which as a header (panel), footer(panel) and in the center for inherited page content. The problem I am running into is with ResourceReferences (Perhaps this isn't even the right way). I am looking for a solution which will allow me to do the following:

  1. Have a single directory for globally used images, js, css
  2. Register (or not) those resources so that they can be accessible from any inherited page or sibling pages to BasePage I might create in the future
  3. Allow those resources to be accessible within CSS and JS (e.g. urls to images)

So far I have read through several examples which show how to package resource for a component or application level scope, but none that seem to address all 3 issues I am looking for help with. It is critical that I don't have to copy globally used images (edit icon, logos, etc) into each component package for referencing, and it would be nice for maintenance reasons that these bindings be made in one place globally for easy reference and updating.

4

1 回答 1

7

自 Wicket 1.4 以来,这种情况发生了显着变化。请参阅Wicket Wiki 中的“使用资源添加 Javascript 或 CSS”

要使图像和其他资源可全局访问(尤其是来自 CSS 和 JS 文件),请将它们挂载到应用程序的 init() 方法中:

mountSharedResource("/images/submit.jpg", new ResourceReference(MyComponent.class, "foo.jpg").getSharedResourceKey());

绝对不需要以任何方式复制资源。资源不必与组件本身位于相同的包中。在我们的应用程序中,我们将全局使用的资源放入一个专用包(例如 com.example.myapp.images)并在其中放入一个类(例如 ImagesScope.java)——对于 JS 和 CSS 也是如此。

对于图像,您不需要ResourceReference,因为您不需要在代码中呈现的那些引用(org.apache.wicket.markup.html.image.Image 除外)。供 JS 和 CSS 使用

add(CSSPackageResource.getHeaderContribution(PanelOne.class, "PanelOne.css"));

顺便说一句,我是GitHub 上一个名为 wicketstuff-merged-resources 的小库的作者。使用此库,您可以跳过应用程序的 init() 中的手动挂载,而使用注释。

编辑:更新链接。不幸的是,wicketstuff wiki 中的文档现在似乎消失了。不过我们的博客上有一些文章

于 2009-10-27T18:11:34.547 回答