在 Wicket 应用程序中包含 CSS 和 JS 文件 [英] Including CSS and JS files in Wicket apps

查看:37
本文介绍了在 Wicket 应用程序中包含 CSS 和 JS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用 Wicket 框架,并在我公司的一个内部项目中试用它.我们有自己的主题 CSS 文件和一个基于 Dojo 构建的用于构建小部件的 JavaScript 库.

I'm a first timer with the Wicket framework and trying it out for an internal project in my company. We have our own CSS files for themes and a JavaScript library built on Dojo for constructing widgets.

我有两个关于包含这些外部资源的问题:

I have two questions about including these external resources:

  1. 这些资源文件夹应该放在哪里?它们是直接放在应用程序下,还是应该与 HTML 文件一起放在 Java 包文件夹中?

  1. Where should these resource folders be located? Do they go directly under the application, or should they be placed in the Java package folder along with the HTML files?

部分中链接 CSS 和 JS 的标准方式是否有效?

Will the standard way of linking CSS and JS in the <head> section work?

我的项目使用 Wicket 1.5.

My project uses Wicket 1.5.

推荐答案

正如 jbrookover 所暗示的,过去有两种方法可以包含 CSS 和 JS.一种是使用 标签,像这样:

As jbrookover hinted, there used to be two ways to include CSS and JS. One is to use <wicket:head> tags, like this:

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

第二种方法是包含标题贡献者,如下所示:

The second method was to include header contributors, like this:

// From v1.3; deprecated in v1.4 and removed in v1.5
add(HeaderContributor.forJavaScript(Foo.class, "yourScripts.js"));

// From v1.4; removed in v1.5
JavascriptPackageResource.getHeaderContribution(Foo.class, "yourScripts.js")

实际上还有第三种更复杂的方法,它涉及编写自定义标头贡献者和 renderHead() 方法.由于您使用的是 1.5 版,因此第二种方法不可用,您必须从 <wicket:head> 标签或复杂方式的稍微修改版本中进行选择.请参阅 Wicket wiki 的迁移到 Wicket 1.5"页面;具体来说,从这里开始的三个部分.

There was actually a third, more complicated way, too, which involved writing a custom header contributor and renderHead() method. Since you're using version 1.5, the second method is unavailable, and you'll have to choose from the <wicket:head> tags or a slightly modified version of the complicated way. See the Wicket wiki's "Migrating to Wicket 1.5" page; specifically, the three sections that start here.

这篇关于在 Wicket 应用程序中包含 CSS 和 JS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆