December 31, 2006 on 6:09 am | In Java |
JavaSercer Pages At the top of the page, the taglib directive is used to identify the library containing all custom actions, as in previous chapters. Then follows the first custom action for localization: . It’s described in Table 11.3. Table 11.3, Attributes for Attribute Name Java Type Request-Time Value Accepted Description id String No Mandatory. The name used to reference the LocaleBean instance. bundleName String Yes Mandatory. The base name for text resource properties files. supportedLangs String Yes Mandatory. A comma-separated list of language/country codes. The first code is used as the default language. This innocent-looking action does a number of things. First, it looks for a LocaleBean with the name specified by the id attribute in the session scope, and creates one if it doesn’t exist. The LocaleBean, described in Table 11.4, handles all localization tasks. It can be used as-is, as you will soon see, but in most cases it’s used indirectly by other custom actions in the set of localization actions. The action then asks the implicit request object for the list of locales specified by the Accept-Language header, and uses that list to set the bean’s requestLocales property. It also looks for a request parameter named language, and if it’s present, it uses the value to set the corresponding language property in the bean. Finally, it sets the bean’s supportedLangs property to the value of the action attribute with the same name. Both the language property and the supportedLangs property take a value that’s either just a language code, or a language code plus a country code separated by a dash (e.g., Es-MX). As shown in Example 11.1, you can specify a number of supported languages as a comma-separated list of codes. The final attribute is called bundleName; this attribute is the base name for a set of ResourceBundle properties files, as described in the first section of this chapter. Table 11.4, Properties for com.ora.jsp.bean.locale.LocaleBean Property Name Java Type Access Description bundleName String write The base name for the properties files charset String write The charset used to decode parameters language String read/write The language code for the selected locale locale java.util.Locale read The locale, selected based on other properties requestLocales java.util.Locale[] write The locales received with the request supportedLangs String write A comma-separated list of language codes With all these properties set, the bean can decide which locale to use for the user requesting the page. The first time the page is requested, the language property is not set, so it compares the language specified by each locale in the requestLocales property to the set of languages in the supportedLangs property, and selects the first locale that is supported. Since the request locales are ordered by preference, the locale with the highest ranking that represents a supported language is selected. As you will soon see, the user can also request this page with a specific language specified by the language parameter. In this case, the action sets the corresponding bean property and the bean uses this value to select the locale, assuming it’s one of the supported languages. If neither the request locales nor the explicitly specified language is supported, the bean selects a locale that represents the first language listed in the supportedLanguages property. page 154
Hint: If you are looking for high quality webhost to host and run your jsp application check Vision web hosting jsp services
Sorry, the comment form is closed at this time.