官术网_书友最值得收藏!

Standard resource locations

JSF 2.0 introduced standard resource locations. Resources are artifacts a page or JSF component needs to render properly. Resource examples include CSS stylesheets, JavaScript files, and images.

In JSF 2.0 and newer versions, resources can be placed in a subdirectory under a folder called resources, either at the root of the WAR file or under its META-INF directory. By convention, JSF components know they can retrieve resources from one of these two locations.

In order to avoid cluttering the resources directory, resources are typically placed in a subdirectory. This subdirectory is referred to from the library attribute of JSF components.

For example, we could place a CSS stylesheet called styles.css under /resources/css/styles.css.

In our JSF pages, we could retrieve this CSS file using the <h:outputStylesheet> tag, as follows:

<h:outputStylesheet library="css"  name="styles.css"/> 

The value of the library attribute must match the subdirectory where our stylesheet is located.

Similarly, we could have a JavaScript file under /resources/scripts/somescript.js and an image under /resources/images/logo.png, and we could access these resources as follows:

<h:graphicImage library="images" name="logo.png"/>

And:

<h:outputScript library="scripts" name="somescript.js"/> 

Notice that, in each case, the value of the library attribute matches the corresponding subdirectory name under the resources directory, and the value of the name attribute matches the resource's file name.

主站蜘蛛池模板: 辽宁省| 达孜县| 瓦房店市| 泰州市| 英超| 新宁县| 万安县| 柏乡县| 永州市| 涟水县| 嘉义县| 都匀市| 乌审旗| 三台县| 玉龙| 兖州市| 镇沅| 洛隆县| 阿拉善右旗| 彩票| 龙井市| 新兴县| 寻乌县| 凌海市| 辉县市| 兴国县| 白玉县| 周口市| 上犹县| 博湖县| 台南市| 秭归县| 泰兴市| 桓仁| 西峡县| 岱山县| 西乌珠穆沁旗| 白银市| 正定县| 石首市| 旺苍县|