关于JSF2.0的Resources

13 篇文章 0 订阅
8 篇文章 0 订阅
关于Resources即使英文的介绍资料也不是很多,发现两篇不错的,收藏以下。

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


Resources jsf-2-0.jpg

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:

  1. Add the line
    <message-bundle>name of a resource bundle used in your application</message-bundle>
    inside the application element of faces-config.xml
  2. Inside each localized version of that resource bundle, place a name/value pair
    javax.faces.resource.localePrefix=prefix
          
  3. Place the matching resources into resources/ prefix/library/...

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.)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值