在JSF <h:outputStylesheet>,<h:outputScript>和<h:graphicImage>组件具有library属性.这是什么以及如何使用它?Web上有很多示例,它们使用如下公共内容/文件类型css,js以及img(或image)作为库名称,具体取决于所使用的标记:
<h:outputStylesheet library="css" name="style.css" />
<h:outputScript library="js" name="script.js" />
<h:graphicImage library="img" name="logo.png" />
Run Code Online (Sandbox Code Playgroud)
它有用吗?library这些示例中的值似乎只是重复标记名称已经表示的内容.对于<h:outputStylesheet>它来说,基于标签名称已经很明显它代表了一个"CSS库".与以下内容有什么不同,它们的工作方式相同?
<h:outputStylesheet name="css/style.css" />
<h:outputScript name="js/script.js" />
<h:graphicImage name="img/logo.png" />
Run Code Online (Sandbox Code Playgroud)
此外,生成的HTML输出有点不同.给定URL模式的上下文路径/contextname和FacesServlet映射*.xhtml,前者生成以下HTML,其库名称为请求参数:
<link rel="stylesheet" type="text/css" href="/contextname/javax.faces.resource/style.css.xhtml?ln=css" />
<script type="text/javascript" src="/contextname/javax.faces.resource/script.js.xhtml?ln=js"></script>
<img src="/contextname/javax.faces.resource/logo.png.xhtml?ln=img" alt="" />
Run Code Online (Sandbox Code Playgroud)
而后者在URI的路径中生成以下带有库名的HTML:
<link rel="stylesheet" type="text/css" href="/contextname/javax.faces.resource/css/style.css.xhtml" />
<script type="text/javascript" src="/contextname/javax.faces.resource/js/script.js.xhtml"></script>
<img src="/contextname/javax.faces.resource/img/logo.png.xhtml" alt="" />
Run Code Online (Sandbox Code Playgroud)
后一种方法在事后看来也比前一种方法更有意义.该library属性究竟有用吗?
我不能使用我自己的图标作为主要的p:commandButton.我的代码是:
<p:commandButton value="Cancel" action="#{userBb.cancel()}"
icon="ui-icon-myCancel" />
Run Code Online (Sandbox Code Playgroud)
css是:
.ui-icon-myCancel{
background-image: url(images/cancel_16.png) !important;
}
Run Code Online (Sandbox Code Playgroud)
文件夹的结构是普通的: /resources/images/cancel_16.png
结果我得到: 
当我尝试:
.ui-state-default .ui-icon .ui-icon-myCancel{
background-image: url(images/cancel_16.png) !important;
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
当我看萤火虫报告时,有节跨度
<span class="ui-button-icon-left ui-icon ui-c ui-icon-myCancel"></span>
Run Code Online (Sandbox Code Playgroud)
有:
.ui-state-default .ui-icon {
background-image: url("/WarPort08_02b/javax.faces.resource/images/ui-icons_38667f_256x240.png.xhtml?ln=primefaces-aristo");
Run Code Online (Sandbox Code Playgroud)
我看过这个解释,其他人却没有找到答案.
当我尝试p:commandLink with h:graphicImage图标是可见的,但它是一个图像作为按钮/链接.