由JSF在css中加载背景图像

时间:2015-02-15 16:57:42

标签: css jsf jsf-2

这是我的css文件registrationStyle.css

body{
    background-image: url("#{resources['images/blue.jpg']}");
}

我的JSF页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>User Registration</title>
        <h:outputStylesheet library="css" name="registrationStyle.css"/>
</h:head>
<h:body>
    This is registration page
</h:body>
</html>

项目结构:

enter image description here

但它无法显示图像!

更新

我想使用<h:graphicImage tage:

<h:graphicImage name="images/t1.jpg" library="default"/>

我试过这个:

<h:graphicImage name="t1.jpg" library="images"/>

但它说Unable to find resource default, images/t1.jpg

enter image description here

1 个答案:

答案 0 :(得分:2)

h:outputStylesheet用于加载CSS文件,要在JSF页面中包含图像文件,您应该使用h:graphicImage标记,如下所示:

<h:graphicImage name="blue.jpg" library="images"/>

<强>更新

为了加载背景图像,最好的解决方案是遵循Tiny的建议(在评论中)并使用:

body{
    background-image: url("#{resource['images/blue.jpg']}");
}

另见: