【问题标题】:resource listing资源列表
【发布时间】:2012-07-20 14:09:48
【问题描述】:

我正在编写 wicket webapp。我想:

  1. 列出所有资源 - 文件夹中的 videoPreview
  2. 预览
  3. 添加链接以显示在主预览面板中。

我阅读了很多并查看了有关资源的示例,但似乎无法理解。我写了这么有趣的代码:

        RepeatingView rv = new RepeatingView("showVideo");
    add(rv);
    File vidPrevDir = (new File("data/catalog/"+product+"/videoPreview"));
    File[] list = vidPrevDir.listFiles();

    for (File file : list) {
        final String previewFile = file.getName();
        AjaxLink link = new AjaxLink(rv.newChildId()){              
            @Override
            public void onClick(AjaxRequestTarget target) {
                container.name="iframe";
                container.attrs.clear();
                container.attrs.put("class", "viewPanel");
                container.attrs.put("allowfullscreen", "yes");
                container.attrs.put("src", "http://www.youtube.com/embed/"+previewFile.substring(previewFile.indexOf("___"), previewFile.length()-4));
                target.add(container);                  
            }

        };
        rv.add(link);
        link.add(new Image("videoPreview", product+"/videoPreview/"+file.getName()));
    }

在我调用的应用程序中 getResourceSettings().addResourceFolder("数据");

这是工作,但当我看到它时我感觉很糟糕。所以我的问题是如何在检票口中制作这样的东西?也许有资源列表或 java.io.File->wicket.Image 转换器?

【问题讨论】:

  • 你关心代码的哪一部分?
  • 首先列出目录中的文件,然后进行文件->构造文件名->图像转换。所以路径被构建了两次。我想我必须通过已经存在的文件/URL 获取图像,或者我必须直接列出资源。最后一个更可取,因为我可以移动资源。但是找不到在某些路径中列出资源的方法。

标签: image file resources wicket directory-listing


【解决方案1】:

我只找到内置方法:

ServletContext 上下文 = WicketApplication.get().getServletContext(); 设置 productList = context.getResourcePaths("/catalog");

它列出文件名,而不是资源,但它是更可取的方法,然后我使用有问题。

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多