我可以使用EL外部CSS文件与JSF吗? [英] Can I use EL for external CSS files with JSF?

查看:250
本文介绍了我可以使用EL外部CSS文件与JSF吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我目前的JSF项目的外部样式表中,有外部资源的硬编码链接,例如

  .someId { background-image:url(/context/resources/images/example.jpg); }在JSF xhtml文档中,我可以使用EL表达式,如$ {request.contextPath},但是如何使用$ {request.contextPath}可以EL处理应用于CSS文件吗?



(相关:






上下文路径的硬编码有一个缺点:Web应用程序的上下文路径 - / context 在部署时通过修改web.xml(或通过重命名Web应用程序归档文件,如果没有在web.xml中指定上下文),但是CSS文件中的资源的链接仍指向不变的硬编码上下文,并导致资源找不到错误。

解决方案

我把CSS图片总是放在CSS文件夹的子文件夹中。例如




  • /resources/css/style.css

  • / resources / css / images / example .jpg



这样你就像

  .someId {background-image:url(images / example.jpg); } 

是的,它们是相对于CSS文件本身的URL而不是主JSF / HTML页面。


In external style sheets of my current JSF project, there are hard-coded links to external resources like

.someId { background-image:url(/context/resources/images/example.jpg); }

In the JSF xhtml documents, I could use EL expressions like ${request.contextPath} but how can EL processing be applied to CSS files?

(Related: How can I embed an CSS background image link with JSF?)


Hard-coding of context paths has a disadvantage: the context path - /context in the example - of a web application can be changed at deploy time by modifying the web.xml (or by renaming the web application archive file if no context is specified in web.xml), but links to resources in the CSS files would still point to the unchanged hard coded context, and cause resource not found errors.

解决方案

I put the CSS images always in a subfolder of the CSS folder. E.g.

  • /resources/css/style.css
  • /resources/css/images/example.jpg

This way you just end up like

.someId { background-image:url(images/example.jpg); }

Yes, they are resolved relative to the URL of the CSS file itself, not to the main JSF/HTML page.

这篇关于我可以使用EL外部CSS文件与JSF吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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