使用Wicket在CSS中引用的图像数百张图像 [英] Images referencing in CSS with Wicket for hundreds of images

查看:127
本文介绍了使用Wicket在CSS中引用的图像数百张图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个好的帖子,我们可以使用像这样的单个图像:

As from another nice posts, we can use something like this for 1 single image:

mountSharedResource("/images/logo.gif", new ResourceReference(ImageScope.class, "logo.gif").getSharedResourceKey());

但是如果我们有100张图片需要共享呢?要映射他们1 by 1是没有办法。有没有一些不错的方式如何实现自动安装1目录的所有图像?

But what if we have 100 images needed to be shared ? To map them 1 by 1 is the no way actually. Is there some nice way how to achieve mounting of all images of 1 directory automatically ?

如果没有,我想在写一些支持在一个循环中的mountSharedResource自动对于驻留在具体图像目录中的所有图像。但实际上我不知道这是否正确的方向。

If not, I am thinking about to write some support doing the mountSharedResource in a loop automatically for all images residing in the concrete image directory. But actually I am not sure if it's the right direction.

谢谢。

推荐答案

好吧,我解决了这个问题:

Well, I solved the issue by this:

private void mountResources(Class clazz, String directory) {
    java.net.URL url = clazz.getResource(clazz.getSimpleName() + ".class");

    File[] files = new File(url.getPath()).getParentFile().listFiles();

    for (int i=0; i< files.length; i++) {
        String fileName = files[i].getName();
        if (!fileName.endsWith("class")) {
            mountSharedResource("/" + directory + "/" + fileName, new ResourceReference(clazz, fileName).getSharedResourceKey());
        }
    }
}

    mountResources(ImagesScope.class, "images");
    mountResources(FontsScope.class, "fonts");
    mountResources(JsScope.class, "js");

但令人难以置信的是Wicket不支持内部。我很惊讶。为了安装整个包的书签页面,我们有mount(path,packageName),但是对于资源没有东西(如果我理解的话)。

But it's unbelievable that Wicket doesn't support it somehow internally. I am quite surprised. For mounting bookmarkable pages for the whole package we have mount(path, packageName), but for resources nothing (if I understand it right).

这篇关于使用Wicket在CSS中引用的图像数百张图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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