From:http://www.informit.com/articles/article.aspx?p=1606899&seqNum=2
原来这里有中文版,jsf核心编程的内容:http://book.51cto.com/art/201111/302930.htm
还有一篇blog:http://137.254.16.27/rlubke/entry/jsf_2_0_new_feature5
You can include a stylesheet in the usual way, with an HTML link tag. But that is tedious if your pages are at varying directory nesting levels—you would always need to update the stylesheet directory when you move a page. More importantly, if you assemble pages from different pieces—as described in Chapter 5—you don't even know where your pieces end up.
Since JSF 2.0, there is a better way. You can place stylesheets, JavaScript files, images, and other files into a resources directory in the root of your web application. Subdirectories of this directory are called libraries. You can create any libraries that you like. In this book, we often use libraries css,images, and javascript.
To include a stylesheet, use the tag:
<h:outputStylesheet library="css" name="styles.css"/>
The tag adds a link of the form
<link href="/context-root/faces/javax.faces.resource/styles.css?ln=css" rel="stylesheet" type="text/css"/>
to the header of the page.
To include a script resource, use the outputScript tag instead:
<h:outputScript name="jsf.js" library="javascript" target="head" />
If the target attribute is head or body, the script is appended to the "head" or "body" facet of the root component, which means that it appears at the end of the head or body in the generated HTML. If there is no target element, the script is inserted in the current location.
To include an image from a library, you use the graphicImage tag:
<h:graphicImage name="logo.png" library="images"/>
There is a versioning mechanism for resource libraries and individual resources. You can add subdirectories to the library directory and place newer versions of files into them. The subdirectory names are simply the version numbers. For example, suppose you have the following directories:
resources/css/1_0_2 resources/css/1_1
Then the latest version (resources/css/1_1) will be used. Note that you can add new versions of a library in a running application.
Similarly, you can add new versions of an individual resource, but the naming scheme is a bit odd. You replace the resource with a directory of the same name, then use the version name as the file name. You can add an extension if you like. For example:
resources/css/styles.css/1_0_2.css resources/css/styles.css/1_1.css
The version numbers must consist of decimal numbers, separated by underscores. They are compared in the usual way, first comparing the major version numbers and using the minor numbers to break ties.
There is also a mechanism for supplying localized versions of resources. Unfortunately, that mechanism is unintuitive and not very useful. Localized resources have a prefix, such asresources/de_DE/images, but the prefix is not treated in the same way as a bundle suffix. There is no fallback mechanism. That is, if an image is not found in resources/de_DE/images, thenresources/de/images and resources/images are not consulted.
Moreover, the locale prefix is not simply the current locale. Instead, it is obtained by a curious lookup, which you enable by following these steps:
<message-bundle>name of a resource bundle used in your application</message-bundle>inside the application element of faces-config.xml
javax.faces.resource.localePrefix=prefix
For example, if you use the message bundle com.corejsf.messages, and the filecom.corejsf.messages_de contains the entry
javax.faces.resource.localePrefix=german
then you place the German resources into resources/german. (The prefix need not use the standard language and country codes, and in fact it is a good idea not to use them so that you don't raise false hopes.)