本文介绍了Wicket& CSS资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在找,我找不到一个虚拟的指南,添加我自己的CSS到Wicket网站项目。但在我开始之前...我是相当新的适当的java开发,所以当我说Dummy的指南我真的意思是!这里简单清楚的解释非常感谢!

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!

我从这里开始这个指南(),并且运行正常。接下来,我想添加我自己的CSS,并开始搞砸它。我快走了。主要是因为我没有一个线索如何在java中做这个(我来自一个C#/ asp.net背景)。

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).

无论如何,那些知道Apache Wicket将会知道这一点,但快速启动的源代码创建在一个地方,如下 project / src / main / java / com / xyz

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

我推测我可以做的是在这里添加一个CSS文件夹...所以我创建了一个示例CSS,我陷入了这样:

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;
}

然后我删除了我的homepage.html中的Wicket默认css,并将其更改为参考矿如下:

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" />

但是我的页面没有考虑conor.css ...显然,做一些错误,但不能找到一个一步一步的指导为一个java假人(也就是我!)。

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!).

我读过的东西,你需要安装web工具eclipse 。我不知道这是什么用于我或为什么它会指示我的页面使用CSS。

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.

任何帮助都非常感谢!

推荐答案

Wicket解析

在您的情况下,您尝试链接到位于您的标记中的资源,并且尝试建立正确的链接,您必须帮助Wicket了解您的标记。 Java类路径。这与Web上下文根(位于src / main / webapp)不同。类路径资源和Web上下文资源之间的区别是Wicket负责并控制对类路径资源的访问,并且您的容器(即jetty,tomcat,glassfish等)负责和控制访问Web上下文资源。

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.

例如,当一个资源在Wicket的权限范围内,我们可以做它的各种事情,如变量替换,压缩,缩小,聚集。这些东西是Wicket的一部分。

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.

现在对你的问题,因为你没有告诉Wicket链接的资源在它的控制下,Wicket假设你想容器来处理这些。要减轻此情况,您应该在< link> 标记周围添加< wicket:link> )。

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>

< wicket:link> 告诉Wicket寻找附带的资源并尝试在Java类路径上解决它们。

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

这篇关于Wicket&amp; CSS资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:00