[英]Wicket - Relative Image Path without Mounting Page
我在图像相对路径和Wicket中未安装页面方面有一些问题。
将此代码放入通用Page(例如MyPage.java)中:
final DatePicker<Date> date = new DatePicker<Date>("date",true);
date.setButtonImage("img/calendar.gif");
img目录存储在WebContent目录中。
除非我在WebApplication中装入页面,否则无法正确显示图像。 在不装入页面的情况下,必须从java类路径开始考虑相对URL。
如何在不装入页面的情况下从WebContent构建正确的图像URL?
谢谢
如果您需要路径,可以使用
date.setButtonImage(UrlUtils.rewriteToContextRelative("img/calendar.gif", getRequestCycle()));
这就是ContextImage的工作方式。 如果您的DatePicker将接受其他组件作为图像,则可以直接使用此类。
在Google上搜索后,我找到了一个简单的解决方案。
ServletContext servletContext = WebApplication.get().getServletContext();
String contextPath = servletContext.getContextPath();
接着
date.setButtonImage(contextPath+"/img/calendar.gif");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.