Вы находитесь на странице: 1из 24

11

Enhancing the Application’s Usability

Copyright © 2007, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do


the following:
• Internationalize an application by using resource
bundles
• Use the JSF loadBundle tag to reference a
resource bundle
• Use Application Development Framework (ADF)
declarative validators
• Use ADF control hints

11-2 Copyright © 2007, Oracle. All rights reserved.


Internationalization

• Internationalization is the support for multiple


locales (i18n).
• Localization is the process in which support for a
specific locale is added.
• ADF Faces supports internationalization and
provides localization support for English, German,
Spanish, French, and more.

11-3 Copyright © 2007, Oracle. All rights reserved.


Resource Bundles

• Resource bundles contain locale-specific strings


used in an application.
• Translation strings can include parameters.
UIResources.properties
sr.browserTitle=SRDemo Sample Application
sr.about=About this sample
sr.copyright=\u00a9 Oracle Corp, 2006
sr.contact=Contact Us

UIResources_de.properties
sr.browserTitle=SRDemo Beispielanwendung
sr.about=Über dieses Beispiel
sr.copyright=\u00a9 Oracle Corp, 2006
sr.contact=Kontakt

11-4 Copyright © 2007, Oracle. All rights reserved.


11-5 Copyright © 2007, Oracle. All rights reserved.
Internationalizing an Application

1. Create a base resource bundle containing all text


strings that are not part of the components
themselves. The bundle should be in the default
language of the application.
2. Use <f:loadBundle …> to reference the resource
bundle.
3. Create a localized resource bundle for each locale
supported by the application.
4. Register the locales with the application.
5. Register the bundle used for error messages.

11-6 Copyright © 2007, Oracle. All rights reserved.


Using Resource Bundles

• Use <f:loadBundle …> to reference the resource


bundle.
• Only the name of the default resource bundle
needs to be specified. Translations are looked up
by appending _<language code> to the name.
• Translatable strings are referenced by their key in
the resource bundle.
<f:view>
<f:loadBundle basename="sr.view.resources.UIResources"
var="res"/>
<af:document title="#{res['srdemo.browserTitle']}">

</f:view>

11-7 Copyright © 2007, Oracle. All rights reserved.


Handling Error Messages

Use a property resource bundle to replace standard


error-message texts:
Create a resource bundle containing key-value pairs
for replacement of error-message texts.
• In faces-config.xml, click the Overview tab.
• Click Application.
• In Message Bundle,
add the path to the
message resource
bundle.
• Use h:messages
tag to display
messages.

11-8 Copyright © 2007, Oracle. All rights reserved.


11-9 Copyright © 2007, Oracle. All rights reserved.
Control Hints and Validation

Declarative validation rules for data controls and


bindings:
• Provide a consistent
user experience
• Are extensible for complex
application validation
• Are metadata based
Control hints for data controls
and bindings include:
• Labels
• Date and currency
formatting

11-10 Copyright © 2007, Oracle. All rights reserved.


Using Control Hints

• Centralize UI settings across clients


• Reduce coding
• Increase consistency
• Hints include:
– Label Text
– Tooltip Text
– Format mask
– Display Height and Display Width

11-11 Copyright © 2007, Oracle. All rights reserved.


Accessing Control Hints

• Part of the ADF Model


• Set at the Entity Metadata level

11-12 Copyright © 2007, Oracle. All rights reserved.


Control Hint Properties

11-13 Copyright © 2007, Oracle. All rights reserved.


11-14 Copyright © 2007, Oracle. All rights reserved.
ADF Declarative Validation

• Declarative rules are enforced in the model.


• The standard set of rules include:
– Compare
– List
– Range
– Length
– Expression
• Error messages are returned through the message
bundle mechanism.
• The message bundle can be internationalized.

11-15 Copyright © 2007, Oracle. All rights reserved.


Adding Validation

11-16 Copyright © 2007, Oracle. All rights reserved.


Internationalizing Control Hints

11-17 Copyright © 2007, Oracle. All rights reserved.


Internationalizing the Message Bundle
(Control Hints)

1. Right-click the message bundle class.


2. Select refactor and duplicate the class.
3. Append the language identifier to the class name:
– ServiceRequestsMsgBundle.java
– ServiceRequestsMsgBundle_fr.java
4. Make language (or locale) changes in the new
class.

11-18 Copyright © 2007, Oracle. All rights reserved.


Internationalizing the Message Bundle
(Control Hints): Example

static final Object[][] sMessageStrings =


{
{ "assignedDate_TOOLTIP", "The date the service requests was
assigned" },
{ "assignedDate_LABEL", "Assignment Date:" },
{ "assignedDate_FMT_FORMATTER",
"oracle.jbo.format.DefaultDateFormatter" },
{ "assignedDate_FMT_FORMAT", "MM-dd-yyyy" }};

static final Object[][] sMessageStrings =


{
{ "assignedDate_TOOLTIP", “Date à laquelle la demande a été
assignée" },
{ "assignedDate_LABEL", “Date d’assignation" },
{ "assignedDate_FMT_FORMATTER",
"oracle.jbo.format.DefaultDateFormatter" },
{ "assignedDate_FMT_FORMAT", "MM-dd-yyyy" }};

11-19 Copyright © 2007, Oracle. All rights reserved.


Internationalizing the Message Bundle
(Control Hints)

11-20 Copyright © 2007, Oracle. All rights reserved.


Internationalized Error Messages

<af:messages bindings= ...

11-21 Copyright © 2007, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


• Internationalize an application by using resource
bundles
• Use the JSF loadBundle tag to reference a
resource bundle
• Add ADF declarative validators to an application
• Use ADF control hints

11-22 Copyright © 2007, Oracle. All rights reserved.


Practice Overview:
Internationalizing an Application

This practice covers the following topics:


• Adding declarative validation to the model
• Using the resource bundle to internationalize the
application
• Using a message bundle to internationalize a
message

11-23 Copyright © 2007, Oracle. All rights reserved.


11-24 Copyright © 2007, Oracle. All rights reserved.

Вам также может понравиться