jsf-2 - background-image: url ("") 在 CSS h:outputStylesheet 没有加载

标签 jsf-2 resources background-image outputstylesheet

这个问题在这里已经有了答案:





How to reference JSF image resource as CSS background image url

(2 个回答)


5年前关闭。




抱歉,如果问题没有正确提出。图像在 struts 项目中显示良好,但在 JSF2 项目中显示不正常。所有的 css 和按钮都呈现良好 except image that has url in css .

文件夹结构

resources -> css -> bootstrap.min.css
resources -> img -> glyphicons-halflings.png

bootstrap.min.css
background-image: url("../img/glyphicons-halflings.png");

1 -
如果我使用 <h:outputStylesheet library="css" name="bootstrap.min.css"/>生成的背景图片网址是 http://localhost:8000/img/glyphicons-halflings.png因此图像未加载。应该是 http://localhost:8000/resources/img/glyphicons-halflings.png
2 - 如果我使用 <link href="#{request.contextPath}/resources/css/bootstrap.min.css" rel="styleSheet" type="text/css"/>

Firefox -> Firebug -> Net tab {resources added multiple times}
http://localhost:8000/resources/resources/img/glyphicons-halflings.png

不知道如何加载 css 中的图像并应用于类。

将编辑图标显示为单击下一页的链接。
 <h:outputLink value="edit.xhtml" >
                            <i class="icon-edit" ></i>
                            <f:param name="id" value="#{person.id}"/>
                        </h:outputLink>

img

最佳答案

您应该使用 EL 变量 #{resource}在 CSS 中指定图像资源。

background-image: url("#{resource['img/glyphicons-halflings.png']}");

也可以看看:
  • How to reference JSF image resource as CSS background image url
  • 关于jsf-2 - background-image: url ("") 在 CSS h:outputStylesheet 没有加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13567714/

    相关文章:

    javascript - 通过 JavaScript 更改 CSS 属性

    css - 背景尺寸 : cover on body is higher than viewport (even though body is 100% height)

    jsf - 点击 bean 方法并重定向 GET 请求

    jsf - 如何在 GlassFish 中更新 Mojarra 版本

    java - "cannot validate component with empty value"HtmlInputText 组件不为空时发出警告

    c++ - 无法在 Xcode 4 c++ 工具中打开文本文件资源?

    java - 两个不同项目的 R.java 的资源 id 冲突

    wpf - XAML:如何定义要在多个项目中使用的数据模板和样式

    java - 从 selectOneMenu JSF 获取值

    ios - UITableView - 背景图像大小和位置问题