【问题标题】:Wicket - Relative Image Path without Mounting PageWicket - 没有安装页面的相对图像路径
【发布时间】:2012-08-21 10:29:18
【问题描述】:

我对 Wicket 中的图像相对路径和未安装页面有一点问题。

将此代码放入通用页面(例如 MyPage.java):

final DatePicker<Date> date = new DatePicker<Date>("date",true);
date.setButtonImage("img/calendar.gif");

img目录存放在WebContent目录中。

除非我在 WebApplication 中安装页面,否则图像无法正确显示。 在不挂载页面的情况下,必须考虑从java类路径开始的相对url。

如何在不安装页面的情况下从 WebContent 构建正确的图像 url?

谢谢

【问题讨论】:

    标签: image wicket mount


    【解决方案1】:

    如果你需要你可以使用的路径

    date.setButtonImage(UrlUtils.rewriteToContextRelative("img/calendar.gif", getRequestCycle()));
    

    ContextImage 就是这样工作的。如果您的 DatePicker 将接受另一个组件作为图像,您可以直接使用此类。

    【讨论】:

      【解决方案2】:

      在谷歌上搜索后,我找到了一个简单的解决方案。

      ServletContext servletContext = WebApplication.get().getServletContext();
      String contextPath = servletContext.getContextPath();
      

      然后

      date.setButtonImage(contextPath+"/img/calendar.gif");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-25
        • 2013-04-25
        • 2011-08-25
        • 2018-11-05
        • 2010-12-16
        • 1970-01-01
        相关资源
        最近更新 更多