本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7627883
建立时间:2006年5月29日




[Tapestry]Tapestry对图片,CSS和本地化字符串等资源的统一控制研究
软件技术

lhwork 发表于 2006/7/11 17:50:35

Tapestry的每个page需要将引用的图片或CSS写入配置中,比较麻烦,本文提供了一种统一管理各种资源的做法。 一、图片和CSS资源 1,在自定义的ApplicationServlet的init方法中初始化各图片资源: String path = config.getServletContext().getResource("/").getPath();             path = path.substring(path.indexOf("/") + 1);             path = path.substring(path.indexOf("/"));             GlobalAssets.init(path); 2,在GlobalAssets中: public static void init(String contextPath) {           GlobalAssets.path = contextPath;//保存环境路径     } public static IAsset get(String name) {   return new ExternalAsset(GlobalAssets.path + name, null); } 3,在page里可以引用这些公共图片资源: <component id="login" type="ImageSubmit">   <binding name="listener" value="listener:loginSubmit"/>   <binding name="image" value="@test.GlobalAssets@get('imgs/login.gif')"/> </component> 其中绿色部分为应用GlobalAssets的login资源,把login.gif改为login.css即可引用CSS资源。 修订: 1,在BasePage中增加方法getContextAsset public IAsset getContextAsset(String name) {         Resource rootResource = this.getRequestCycle().getInfrastructure()                 .getContextRoot();         Resource resource = rootResource.getRelativeResource(name);         ContextAsset ca = new ContextAsset(this.getRequestCycle()                 .getInfrastructure().getContextPath(), resource,                 new LocationImpl(resource));         return ca;     } 2,在page文件中引用即可 <component id="login" type="ImageSubmit">   <binding name="listener" value="listener:loginSubmit"/>   <binding name="image" value="getContextAsset('/imgs/login.gif')"/> </component> 再修订:请参考我的另一篇文章tapestry绑定的研究与应用 二、本地化字符串资源 如果你的应用是MyApp,则在WEB-INF/下创建一个MyApp_zh_CN.properties,其中可以写入: username=用户名 password=密码 在各个page文件中就可以引用这些中文本地化字符串了。    <component id="username" type="TextField">         <binding name="value" value="username"/>         <binding name="displayName"  value="message:username"/>     </component> 其中粗体部分表示引用本地化字符串资源。


阅读全文(2351) | 回复(-2) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.078 second(s), page refreshed 144795442 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号