This chapter describes how to use the shortDesc
attribute to display tips, and how to display messages for ADF Faces components. This chapter also describes how to provide different levels of help information for users.
This chapter includes the following sections:
Section 19.3, "Displaying Hints and Error Messages for Validation and Conversion"
Section 19.4, "Grouping Components with a Single Label and Message"
ADF Faces provides many different ways for displaying informational text in an application. You can create simple tip text, validation and conversion tip text, validation and conversion failure messages, as well as elaborate help systems.
Many ADF Faces components support the shortDesc
attribute, which for most components, displays tip information when a user hovers the cursor over the component. Figure 19-2 shows a tip configured for a toolbar button.
Along with tips, some ADF Faces components (such as the inputText
component, or the selection components) can display popup hint messages and failure messages used for validation and conversion. You can create two types of messages: component level messages that apply to a specific component, and global-level messages that apply to a page or group of components. Figure 19-3 shows a hint message configured for an Input Date field.
Along with configuring messages for individual component instances, you can create a separate help system that provides information that can be reused throughout the application.You create help information using different types of providers, and then reference the help text from the UI components. The following are the three types of help supported by ADF Faces:
Definition: Provides a help icon (question mark in a blue circle) with the help text appearing when the user mouses over the icon, as shown in Figure 19-4.
Instruction: Depending on the component, this type of help either provides instruction text within the component (as with panelHeader
components), or displays text in the note window that is opened when the user clicks in the component, as shown in Figure 19-5. The text can be of any length.
External URL: You can have a help topic that resides in an external application, which will open in a separate browser window. For example, instead of displaying instruction help, Figure 19-6 shows the Select Skin selectOneChoice
component configured to open a help topic about skins. When a user clicks the selectOneChoice
component, the help topic opens.
For more information about creating help systems, see Section 19.5, "Displaying Help for Components."
Messages can typically be divided into to types: error messages that display when an error occurs in the application, for example when a user enters incompatible information, and informational messages that provide for example, hints for using a component or for completing a task on a page.
Informational messages can range from simple tooltips to comprehensive help systems. Tooltips should be used when the component for which you want to display hints or information does not support help text. However, tooltip text must be very brief. If you have to display more detailed information, or if the text can be reused among many component instances, consider using help text instead.
You create tooltips by configuring the shortDesc
attribute on a component. The value of that attribute then displays in a note window when the user hovers over the component or clicks the component (such as inputText
component), as shown in Figure 19-7.
For more information about tooltips, see Section 19.2, "Displaying Tips for Components."
Error messages use the JSF messaging API. There are two types of error messages: component messages where the message applies to the specific component only, and global messages, where the message applies to more than one component or the whole page.
By default, the noteWindow
component is used for component error messages. When you configure conversion or validation on any input component, validation and conversion hints and errors are automatically displayed in the noteWindow
component. You do not need to add the component to the page.
For example, when users click Help > Give Feedback in the File Explorer application, a dialog displays where they can enter a time and date for a customer service representative to call. Because the inputDate
component contains a converter, when the user clicks in the field, a note window displays a hint that shows the expected pattern, as shown in Figure 19-8. If the inputDate
component was also configured with a minimum or maximum value, the hint would display that information as well. These hints are provided by the converters and validators automatically.
If a user enters a date incorrectly in the field shown in Figure 19-8, an error message is displayed, as shown in Figure 19-9. Note that the error message appears in the note window along with the hint.
If you want to display an error message for a non-ADF Faces component, or if you want the message to be displayed inline instead of the note window, use the ADF Faces message
component. When you use this component, messages are displayed next to the component, as shown in Figure 19-10.
Global messages are by default displayed in a dialog, as shown in Figure 19-11. You do not need to add the popup component to the page.
If instead you want the error messages to display directly on the page, use the messages
component. When you use this component, the messages are displayed in a list at the top of the page, as shown in Figure 19-12.
For more information about error messages, see Section 19.3, "Displaying Hints and Error Messages for Validation and Conversion."
When you want to display more information that can fit in a tooltip, use definition help. When you configure definition help for most components, a help icon is displayed next to the component. The help text is displayed when the mouse hovers over the component, as shown in Figure 19-13.
For more information about definition help, see Section 19.5, "Displaying Help for Components."
When you want to display field-level help, configure an input component to use instruction text. When the user clicks in the component, the help text is displayed in a note window, as shown in Figure 19-14.
When you want to display instructions for a task, configure instruction help for a container component. The text will appear in the header of the component, as shown in Figure 19-15.
Best Practice:
Instruction text for input components should be used only when the typical user may fail to perform a task without assistance. Excessive use of instruction text clutters the page with directions or distracts users with note windows that may also obscure related page elements.
When you need to provide comprehensive help, you can use the help icon to link to an external help system available through a URL.
For more information about instruction and external help, see Section 19.5, "Displaying Help for Components."
You may find it helpful to understand other ADF Faces features before you implement your message components and help functionality. Additionally, once you have added these components to your page, you may find that you need to add functionality such as skinning to change icons and accessibility and using resource bundles to store message text. Following are links to other functionality that message components can use.
Using parameters in text: You can use the ADF Faces EL format tags if you want text displayed in a component to contain parameters that will resolve at runtime. For more information, see Section 3.5.2, "How to Use the EL Format Tags."
Client events: If you want your help topic to launch using JavaScript, you use a listener for a client event. For more information about client-side events, see Section 6.3, "Using JavaScript for ADF Faces Client Events."
Skinning: The icons displayed for messages and help are determined by the skin used by the application. You can change the icons by creating a new skin. For more information, see Chapter 31, "Customizing the Appearance Using Styles and Skins."
Localization: Instead of directly entering text for messages, you can use property files. These files allow you to manage translation of these strings. For more information, see Chapter 32, "Internationalizing and Localizing Pages."
ADF Faces components use the shortDesc
attribute to display a tip when the user hovers the mouse over the component. Input components display the tips in their note window. Other component types display the tip in a standard tip box. This text should be kept short. If you have to display more detailed information, or if the text can be reused among many component instances, consider using help text, as described in Section 19.5, "Displaying Help for Components."
Figure 19-16 shows the effect when the cursor hovers over an inputText
component.
Figure 19-17 shows a tip as displayed for a showDetailItem
component.
You use the shortDesc
attribute on a component to display a tip.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.2, "Displaying Tips for Components."
You may also find it helpful to understand functionality that can be added using other ADF Faces features. For more information, see Section 19.1.2, "Additional Functionality for Message Components."
To define a tip for a component:
In the Structure window, select the component for which you want to display the tip.
In the Properties window, expand the Appearance section and enter a value for the shortDesc
attribute.
Tip:
The value should be less than 80 characters, as some browsers will truncate the tip if it exceeds that length.
If the text to be used is stored in a resource bundle, use the dropdown list to select Select Text Resource. Use the Select Text Resource dialog to either search for appropriate text in an existing bundle, or to create a new entry in an existing bundle. For more information about using resource bundles, see Chapter 32, "Internationalizing and Localizing Pages."
Validators and converters have a default hint that is displayed to users when they click in the associated field. The default hint automatically displays in a note window. For converters, the hint usually tells the user the correct format to use. For validators, the hint is used to convey what values are valid.
For example, in the File Explorer application, when a user clicks in the input date field on the Speak with Customer Service page, a tip is displayed showing the correct format to use, as shown in Figure 19-18.
When the value of an ADF Faces component fails validation, or cannot be converted by a converter, the component displays the resulting FacesMessage
instance.
For example, entering a date that does not match the dateStyle
attribute of the converter results in an error message, as shown in Figure 19-19.
You can override the default validator and converter hint and error messages for either a component instance, or globally for all instances. To define a custom message for a component instance you set attributes to the detail messages to be displayed. The actual attributes vary according to the validator or converter. Figure 19-20 shows the attributes that you can populate to override the messages for the convertDateTime
converter, as displayed in the Properties window.
To define an error message that will be used by all instances of the component, you need to create an entry in a resource bundle that will override the default message.
If you do not want messages to be displayed in the note window, you can use the message
component, and messages will be displayed inline with the component. Figure 19-21 shows how messages are displayed using the message
component.
JSF pages in an ADF Faces application use the document
tag, which among other things, handles displaying all global messages (those not associated with a component) in a popup window. However, if you want to display global messages on the page instead, use the messages
component.
Note:
To format the message using HTML tags, you must enclose the message within <html></html>
tags. For example:
<html><b>error</b> message details</html>
The following HTML tags are allowed in error messages:
<span>
<b>
<a>
<i>
<em>
<br>
<hr>
<li>
<ol>
<ul>
<p>
<tt>
<big>
<small>
<pre>
To override the default validator and converter messages for a single component instance, set values for the different message attributes.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.3, "Displaying Hints and Error Messages for Validation and Conversion."
You may also find it helpful to understand functionality that can be added using other ADF Faces features. For more information, see Section 19.1.2, "Additional Functionality for Message Components."
To define a validator or converter message:
In the Structure window, select the converter or validator for which you want to create the error message.
In the Properties window, expand the Messages section and enter a value for the attribute for which you want to provide a message.
The values can include dynamic content by using parameter placeholders such as {0}, {1}, {2}, and so on. For example, the messageDetailConvertDate
attribute on the convertDateTime
converter uses the following parameters:
{0} the label that identifies the component
{1} the value entered by the user
{2} an example of the format expected by the component.
Tips:
If your application uses bidirectional or right-to-left display, do not start the message with the expected format parameter {2}
, as it may not display correctly in Internet Explorer.
You should try not to display the format parameter {1}
in the message. Displaying the user input might be considered as a security violation.
Using these parameters, you can create the following message:
The date you have entered in the \"{0}\" field is not using the correct date format. Please enter the date as follows: {2}.
The error message would then be displayed as shown in Figure 19-22. Note that you might need to change the value Type
attribute of the converter to match the parameters.
Tip:
Use the dropdown menu to view the property help, which includes the parameters accepted by the message.
If the text to be used is stored in a resource bundle, use the dropdown list to select Select Text Resource. Use the Select Text Resource dialog to either search for appropriate text in an existing bundle, or to create a new entry in an existing bundle. For more information about using resource bundles, see Chapter 32, "Internationalizing and Localizing Pages."
Note:
The message text is for the detail message of the FacesMessage
object. If you want to override the summary (the text shown at the top of the message), you can only do this globally. For more information, see Section 19.3.2, "How to Define Custom Validator and Converter Messages for All Instances of a Component."
Instead of changing the message string per component instance with the messageDetail[XYZ]
attributes, you can override the string globally so that the custom string will be displayed for all instances. The global messages are handled by key/value pairs in a message bundle. You can override summary, detail, and hint messages.
To globally override a default validator or converter message:
Refer to Appendix B, "Message Keys for Converter and Validator Messages" to determine the message key for the message you want to override. For example, to override the detail message displayed when the input value exceeds the maximum value length, you would use the key org.apache.myfaces.trinidad.validator.LengthValidator.
, as shown in Section B.3.8, "af:validateLength."
MAXIMUM_detail
Create or open a message bundle. For procedures how to create message bundles, see Section 32.3.1, "How to Create a Resource Bundle as a Property File or an XLIFF File."
Add the key override to the message bundle. For example, to override the message for the input value length, you might add:
org.apache.myfaces.trinidad.validator.LengthValidator.MAXIMUM_detail: Your value exceeds the limit.
If the message bundle is a new resource bundle, you need to register the bundle with the application using the faces-config.xml
file, following the procedures in Section 32.3.5, "How to Register a Resource Bundle in Your Application." However, use the <message-bundle>
tag, rather than the <resource-bundle>
tag.
Instead of having a component display its messages in the note window, use the message
component to display the messages inline on the page. In order for the message
component to display the correct messages, associate it with a specific component.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.3, "Displaying Hints and Error Messages for Validation and Conversion."
You may also find it helpful to understand functionality that can be added using other ADF Faces features. For more information, see Section 19.1.2, "Additional Functionality for Message Components."
To display component messages inline:
In the Structure window, select the component that will display its messages using the message
component. If not already set, enter an ID for the component.
In the Components window, from the Text and Selection panel, drag a Message and drop it where you want the message to be displayed on the page.
Use the dropdown menu for the for
attribute to select Edit.
In the Edit Property dialog, locate the component for which the message
component will display messages. Only components that have their ID set are valid selections.
Note:
The message icon and message content that will be displayed are based on what was given when the FacesMessage
object was created. Setting the messageType
or message
attributes on the message
component causes the messageType
or message
attribute values to be displayed at runtime, regardless of whether or not an error has occurred. Only populate these attributes if you want the content to always be displayed when the page is rendered.
Instead of displaying global messages in a popup window for the page, display them inline using the messages
component.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.3, "Displaying Hints and Error Messages for Validation and Conversion."
You may also find it helpful to understand functionality that can be added using other ADF Faces features. For more information, see Section 19.1.2, "Additional Functionality for Message Components."
To display global messages inline:
In the Components window, from the Text and Selection panel, drag a Messages and drop it onto the page where you want the messages to be displayed.
In the Properties window, set the following attributes:
globalOnly
: By default, ADF Faces displays global messages (messages that are not associated with components) followed by individual component messages. If you want to display only global messages in the box, set this attribute to true
. Component messages will continue to be displayed with the associated component.
inline
: Set to true
to show messages at the top of the page. Otherwise, messages will be displayed in a dialog.
ADF Faces uses the standard JSF messaging API. JSF supports a built-in framework for messaging by allowing FacesMessage
instances to be added to the FacesContext
object using the addMessage(java.lang.String clientId, FacesMessage message)
method. Component-level messages are associated with a specific component based on any client ID that was passed to the addMessage
method, and global-level messages, which are not associated with a component because no client ID was passed to the addMessage
method.
When conversion or validation fails on an EditableValueHolder
ADF Faces component, FacesMessages
objects are automatically added to the message queue on the FacesContext
instance, passing in that component's ID. These messages are then displayed in the note window for the component. ADF Faces components are able to display their own messages. You do not need to add any tags.
Similarly, the document
tag handles and displays all global FacesMessages
objects (those that do not contain an associated component ID), as well as component FacesMessages
. Like component messages, you do not need to add any tags for messages to be displayed.Whenever a global message is created (or more than one component message), all messages in the queue will be displayed in a popup window, as shown in Figure 19-23.
Tip:
While ADF Faces provides messages for validation and conversion, you can add your own FacesMessages
objects to the queue using the standard JSF messaging API. When you do so, ADF Faces will display icons with the message based on the message level, as follows:
By default, ADF Faces input and select components have built-in support for label and message display. If you want to group components and use a single label, wrap the components using the panelLabelAndMessage
component.
For example, the File Explorer application collects telephone numbers using four separate inputText
components; one for the area code, one for the exchange, one for the last four digits, and one for the extension. Because a single label is needed, the four inputText
components are wrapped in a panelLabelAndMessage
component, and the label value is set on that component. However, the input component for the extension requires an additional label, so an outputText
component is used. Example 19-1 shows the JSF code for the panelLabelAndMessage
component.
Example 19-1 panelLabelAndMessage Can Display a Single Label and Help Topic
<af:panelLabelAndMessage labelAndAccessKey="#{explorerBundle['help.telephone']}" helpTopicId="HELP_TELEPHONE_NUMBER" labelStyle="vertical-align: top; padding-top: 0.2em;"> <af:inputText autoTab="true" simple="true" maximumLength="3" columns="3"> <af:convertNumber type="number" integerOnly="true"/> </af:inputText> <af:inputText autoTab="true" simple="true" maximumLength="3" columns="3"> <af:convertNumber type="number" integerOnly="true"/> </af:inputText> <af:inputText autoTab="true" simple="true" maximumLength="4" columns="4"> <af:convertNumber type="number" integerOnly="true"/> </af:inputText> <af:outputText value="#{explorerBundle['help.extension']}"/> <af:inputText simple="true" columns="4"> <af:convertNumber type="number" integerOnly="true"/> </af:inputText> </af:panelLabelAndMessage>
Figure 19-24 shows how the panelLabelAndMessage
and nested components are displayed in a browser.
The panelLabelAndMessage
component also includes an End
facet that can be used to display additional components at the end of the group. Figure 19-25 shows how the telephone number fields would be displayed if the End
facet was populated with an outputText
component.
Use a panelGroupLayout
component within a panelLabelAndMessage
component to group the components for the required layout. For information about using the panelGrouplayout
component, see Section 9.13, "Grouping Related Items."
You set the simple
attribute to true
on each of the input components so that their individual labels are not displayed. However, you may want to set a value for the label attribute on each of the components for messaging purposes and for accessibility.
Tip:
If you have to use multiple panelLabelAndMessage
components one after another, wrap them inside an af:panelFormLayout
component, so that the labels line up properly. For information about using the panelFormLayout
component, see Section 9.7, "Arranging Content in Forms."
Group and wrap components using the panelLabelAndMessage
component. The panelLabelAndMessage
component can be used to wrap any components, not just those that typically display messages and labels.
You use the panelLabelAndMessage
component to group components and display a single label for that group.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.4, "Grouping Components with a Single Label and Message."
You may also find it helpful to understand functionality that can be added using other ADF Faces features. For more information, see Section 19.1.2, "Additional Functionality for Message Components."
To arrange form input components with one label and message:
Add input or select components as needed to the page.
For each input and select component:
Set the simple
attribute to true
.
For accessibility reasons, set the label
attribute to a label for the component.
In the Structure window, select the input or select components created in Step 1. Right-click the selection and choose Surround With > Panel Label And Message.
With the panelLabelAndMessage
component selected, in the Properties window, set the following:
label: Enter the label text to be displayed for the group of components.
for: Use the dropdown menu to choose Edit. In the Edit Property dialog, select the ID of the child input component. If there is more than one input component, select the first component.
Set the for
attribute to the first inputComponent
to meet accessibility requirements.
If one or more of the nested input components is a required component and you want a marker to be displayed indicating this, set the showRequired
attribute to true
.
To place content in the End
facet, drag and drop the desired component into the facet.
Because facets on a JSP or JSPX accept one child component only, if you want to add more than one child component, you must wrap the child components inside a container, such as a panelGroupLayout
or group
component. Facets on a Facelets page can accept more than one component.
Tip:
If the facet is not visible in the visual editor:
Right-click the panelLabelAndMessage
component in the Structure window.
From the context menu, choose Facets - Panel Label And Message >facet name. Facets in use on the page are indicated by a checkmark in front of the facet name.
ADF Faces provides a framework that allows you to create and display three different types of help whose content comes from an external source, rather than as text configured on the component. Because it is not configured directly on the component, the content can be used by more than one component, saving time in creating pages and also allowing you to change the content in one place rather than everywhere the content appears.
You can display help messages in three formats; instruction help, definition help, and external URL help.
Instruction help displays help text in a note window when the focus is on the component. Figure 19-26 shows the help message in a note window.
Usually, you use the instruction help to show instructions about how to use the component. You can also use HTML tags to format the help message, but not all HTML tags are supported (see tag documentation of af:outputFormatted
component for supported HTML tags). Figure 19-27 shows the HTML formatted help message in a note window.
Some components display instruction help as a description within the component. Where instruction help is displayed depends on the component with which it is associated. For example, the panelHeader
and Search panel components display instruction help within the header, as shown in Figure 19-28.
Table 19-1 shows the components that support Instruction help.
Table 19-1 Components That Support Instruction Help
Supported Components | Help Placement | Example |
---|---|---|
Input components, Choose Color, Choose Date, Quick Query |
Note window, on focus only |
|
Select components |
Note window, on hover and focus |
|
Panel Header, Panel Box, Query |
Text below header text |
Definition help is like a standard tip where the content appears in a message box. However, instead of appearing when the user hovers the cursor over the component, definition help provides a help icon (a blue circle with a question mark). When the user hovers the cursor over the icon, the content is displayed as shown in Figure 19-29.
Note that the tip message does not support HTML formatting and the tip message must be less than 80 characters because some older versions of browsers do not support long messages. Table 19-2 shows the components that support definition help.
Table 19-2 Components That Support Definition Help
Supported Components | Help Icon Placement | Example |
---|---|---|
All input components, Select components, Choose Color, Choose Date, Query components |
Before the label, or if no label exists, at the start of the field |
|
Panel Header, PanelBox, Show Detail Header |
End of header text |
|
Panel Window, Dialog |
Next to close icon in header |
|
Columns in table and tree |
Below header text |
External URL help allows you to link to an existing web page for your help content. When the help icon is clicked, the web page opens in a separate browser window, as shown in Figure 19-30. You can also use JavaScript to open the help window based on any client-based event.
For more information about using JavaScript to open the external help, rather than the help icon, see Section 19.5.4, "How to Use JavaScript to Launch an External Help Window."
Help providers store the text of the help (or a URL, in the case of external help) for an application, and are registered in the META-INF/adf-settings.xml
file. ADF Faces supports the following help providers for instruction and definition help:
The ResourceBundleHelpProvider
help provider enables you to create resource bundles that hold the help content.
The ELHelpProvider
help provider enables you to create XLIFF files that get converted into maps.
A managed bean that contains a map of help text strings.
External URL help uses a class that implements the getExternalURL
method.
For more information about creating help providers, see Section 19.5.1, "How to Create Help Providers."
You can also use a combination of the different help providers, or create your own help provider class.
To create help messages, you do the following:
For instruction and definition help, determine which help provider type you want to use (either a resource bundle, an XLIFF file, or a managed bean), and then implement the required artifacts. These help providers will contain the actual help text. For more information, see Section 19.5.1, "How to Create Help Providers."
For external help, you need to create the an external help provider that will contain the URLs to the external content. For more information, see Section 19.5.1.4, "How to Create an External URL Help Provider."
Register the help providers, specifying the unique prefix that will be used to access the provider's help. For more information, see Section 19.5.2, "How to Register the Help Provider."
Have the UI components access the help contained in the providers by using the component's helpTopicId
attribute. A helpTopicId
attribute contains the following:
The prefix that is used by the provider of the help
The topic name
For more information, see Section 19.5.3, "How to Access Help Content from a UI Component."
For external URL help, you can optionally have the help window launch in response to an event, instead of having the user click the help icon. For more information, see Section 19.5.4, "How to Use JavaScript to Launch an External Help Window."
Procedures for creating help providers differ, depending on the type of help provider you want to create. For instruction and definition help, you can use resource bundles, an XLIFF
file, or a managed bean. For external URL help, you create a Java class. You can also create a custom help provider.
The ResourceBundleHelpProvider
class provides a basic HelpProvider
instance. You can store help text within standard resource bundle property files and use the ResourceBundleHelpProvider
class to deliver the content.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
To create resource bundle-based help:
Create a properties file that contains the topic ID and help text for each help topic. The topic ID must contain the following:
The prefix that will be used by this provider, for example, BUNDLE
.
The topic name, for example, PHONE_NUMBER
.
The help type, for example, DEFINITION
.
For example, a topic ID might be BUNDLE_PHONE_NUMBER_DEFINITION
.
If you are using multiple help providers, ensure that you use unique prefix for each help provider.
Note:
All prefixes under which help providers are registered must be unique. It is also not permissible for one prefix to begin with the same characters as another prefix. For example, if help providers have already been registered for the two prefixes AAB
and AC
, then the following prefixes are all invalid and will cause an exception to be thrown at registration time: AABC
, A
, AA
, AC
, ACB
. However, the following are valid: AAD
, AB
, and so on.
UI components access the help content based on the topic name. Therefore, if you use the same topic name for two different types of help, then both types of help will be displayed by the UI component.
Example 19-2 shows an example resource bundle properties file with two topic IDs.
Register the resource bundle as a help provider in the adf-settings.xml
file and then configure the ADF Faces components to use the help. For more information, see Section 19.5.2, "How to Register the Help Provider" and Section 19.5.3, "How to Access Help Content from a UI Component."
You can store the help text in XLIFF XML files and use the ELHelpProvider
class to deliver the content. This class translates the XLIFF file to a map of strings that will be used as the text in the help.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
Create an XLIFF file that defines your help text, using the following elements within the <body>
tag:
<trans-unit>
: Enter the topic ID. This must contain the prefix, the topic name, and the help type, for example, HELP_PHONE_NUMBER_DEFINITION
. In this example, HELP
will become the prefix used to access the XLIFF file. PHONE_NUMBER
is the topic name, and DEFINITION
is the type of help. If you are using multiple help providers, ensure that you use unique prefix for each help provider.
Note:
All prefixes under which help providers are registered must be unique. It is also not permissible for one prefix to begin with the same characters as another prefix. For example, if help providers have already been registered for the two prefixes AAB
and AC
, then the following prefixes are all invalid and will cause an exception to be thrown at registration time: AABC
, A
, AA
, AC
, ACB
. However, the following are valid: AAD
, AB
, and so on.
UI components access the help content based on the topic name. Therefore, if you use the same topic name for two different types of help, then both types of help will be displayed by the UI component.
<source>
: Create as a direct child of the <trans-unit>
element and enter the help text.
<target>
: Create as a direct child of the <trans-unit>
element and leave it blank. This element is used to hold translated help text.
<note>
: Create as a direct child of the <trans-unit>
element and enter a description of the help text.
Example 19-3 shows an example of an XLIFF file that contains two topics.
<?xml version="1.0" encoding="UTF-8" ?> <xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"> <file source-language="en" original="this" datatype="xml"> <body> <trans-unit id="HELP_PHONE_NUMBER_DEFINITION"> <source>Phone Number Definition</source> <target/> <note> We only support calling phone numbers in the United States at this time. </note> </trans-unit> <trans-unit id="HELP_CUST_SERVICE_EMAIL_INSTRUCTIONS"> <source>Customer Service Email Instructions</source> <target/> <note> For security reasons, we strongly discourage the submission of credit card numbers. </note> </trans-unit> </body> </file> </xliff>
Register the XLIFF
file as a help provider in the adf-settings.xml
file and then configure the ADF Faces components to use the help. For more information, see Section 19.5.2, "How to Register the Help Provider" and Section 19.5.3, "How to Access Help Content from a UI Component."
To implement a managed bean provider, create a managed bean that contains a map of strings that will be used as the text in the help. Managed bean help providers use the ELHelpProvider
class to deliver the help.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
Create a managed bean that returns a map of strings, each of which is the ID and content for a help topic, as shown in Example 19-4.
Example 19-4 Managed Bean that Returns a Map of Help Text Strings
public class ELHelpProviderMapDemo { public ELHelpProviderMapDemo() { } /* To use the ELHelpProvider, the EL expression must point to a Map, otherwise * you will get a coerceToType error. */ public Map<String, String> getHelpMap() { return _HELP_MAP; } static private final Map<String, String> _HELP_MAP = new HashMap<String, String>(); static { _HELP_MAP.put("HELP_CUST_SERVICE_EMAIL_DEFINITION", "For security reasons, we strongly discourage the submission of credit card numbers"); _HELP_MAP.put("HELP_PHONE_NUMBER_DEFINITION", "We only support calling phone numbers in the United States at this time"); } }
The first string must contain the prefix, the topic name, and the help type, for
example, HELP_CUST_SERVICE_EMAIL_DEFINITION
. In this example, HELP
will become the prefix used to access the bean. CUST_SERVICE_EMAIL
is the topic name, and D
EFINITION
is the type of help. The second string is the help text. If you are using multiple help providers, ensure that you use unique prefix for each help provider.
Note:
All prefixes under which help providers are registered must be unique. It is also not permissible for one prefix to begin with the same characters as another prefix. For example, if help providers have already been registered for the two prefixes AAB
and AC
, then the following prefixes are all invalid and will cause an exception to be thrown at registration time: AABC
, A
, AA
, AC
, ACB
. However, the following are valid: AAD
, AB
, and so on.
UI components access the help content based on the topic name. Therefore, if you use the same topic name for two different types of help, then both types of help will be displayed by the UI component.
Note:
If you wish to use external URL help, create a subclass of the ELHelpProvider
class. For more information, see Section 19.5.1.4, "How to Create an External URL Help Provider."
Register the managed bean as a help provider in the adf-settings.xml
file and then configure the ADF Faces components to use the help. For more information, see Section 19.5.2, "How to Register the Help Provider" and Section 19.5.3, "How to Access Help Content from a UI Component."
To use an external URL as help, you must implement the getExternalURL
method.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
Create a class that implements the getExternalURL
method.
If you are using a resource bundle based help, ensure that the class that implements the getExternalURL
method extends the ResourceBundleHelpProvider
class.
If you are using XLIFF based or managed bean based help, ensure that the class that implements the getExternalURL
method extends the ELHelpProvider
class.
Example 19-5 shows the DemoHelpProvider
class that extends the ResourceBundleHelpProvider
class.
Example 19-5 Extending the ResourceBundleHelpProvider Class
import javax.faces.component.UIComponent; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import oracle.adf.view.rich.help.ResourceBundleHelpProvider; public class DemoHelpProvider extends ResourceBundleHelpProvider { public DemoHelpProvider() { } @Override protected String getExternalUrl(FacesContext context, UIComponent component, String topicId) { if (topicId == null) return null; if (topicId.contains("HELP_CONTACT_URL")) { return "http://www.oracle.com/us/corporate/contact/index.html"; } else return null; if (topicId.contains("HELP_OTN_URL") ) { return "http://www.oracle.com/technetwork/index.html"; } else return null; } }
Example 19-6 shows the DemoELHelpProvider
class that extends the ELHelpProvider
class.
Example 19-6 Extending the ELHelpProvider Class
import javax.faces.component.UIComponent; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import oracle.adf.view.rich.help.ResourceBundleHelpProvider; public class DemoELHelpProvider extends ELHelpProvider { public DemoELHelpProvider() { } @Override protected String getExternalUrl(FacesContext context, UIComponent component, String topicId) { if (topicId == null) return null; if (topicId.contains("HELP_CONTACT_URL")) { return "http://www.oracle.com/us/corporate/contact/index.html"; } else return null; if (topicId.contains("HELP_OTN_URL") ) { return "http://www.oracle.com/technetwork/index.html"; } else return null; } }
Example 19-5 and Example 19-6 use the HELP_CONTACT_URL
topic ID to open the Oracle Contact home page. To return different URLs, you would have to create separate if
statements. Example 19-5 and Example 19-6 use HELP_OTN_URL
topic ID to open the Oracle Technology Network home page.
Register the class as a help provider in the adf-settings.xml
file and then configure the ADF Faces components to use the help. For more information, see Section 19.5.2, "How to Register the Help Provider" and Section 19.5.3, "How to Access Help Content from a UI Component."
Instead of using one of the ADF Faces help providers, create your own. Create the actual text in some file that your help provider will be able to access and display. To create a Java class help provider, extend the HelpProvider
class. For more information about this class, refer to the Java API Reference for Oracle ADF Faces.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
To create a Java class help provider:
Create a Java class that extends oracle.adf.view.rich.help.HelpProvider
.
Create a public constructor with no parameters. You also must implement the logic to access and return help topics.
This class will be able to access properties and values that are set in the adf-settings.xml
file when you register this provider. For example, all the ADF Faces providers use a property to define the actual source of the help strings.
To access a property in the adf-settings.xml
file, create a method that sets a String
property.
For example:
public void setMyCustomProperty(String arg)
To register the provider, from the META-INF
node, open the adf-settings.xml
file and add the following elements:
<help-provider>
: Use the prefix
attribute to define the prefix that UI components will use to access this help provider. This must be unique in the application.
Note:
If the prefix
attribute is missing, or is empty, then the help provider will be registered as a special default help provider. It will be used to produce help for help topic IDs that cannot be matched with any other help provider. Only one default help provider is permitted. All prefixes under which help providers are registered must be unique. It is also not permissible for one prefix to begin with the same characters as another prefix. For example, if help providers have already been registered for the two prefixes AAB
and AC
, then the following prefixes are all invalid and will cause an exception to be thrown at registration time: AABC
, A
, AA
, AC
, ACB
. However, the following are valid: AAD
, AB
, and so on.
<help-provider-class>
: Create as a child element to the <help-provider>
element and enter the fully qualified class path to the class created in Step 1.
<property>
: Create as a child element to the <help-provider>
element and use it to define the property that will be used as the argument for the method created in Step 3.
<property-name>
: Create as a child element to the <property>
element and enter the property name.
<value>
: Create as a child element to the <property>
element and enter the value for the property.
You register resource, XLIFF, and managed bean help providers, and an external URL help provider in the adf-settings.xml
file.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
In the Applications window, from the META-INF
node, open the adf-settings.xml
file.
Click the Source tab, and add the following elements:
<help-provider>
: Use the prefix
attribute to define the prefix that UI components will use to access this help provider. This must be unique in the application.
Note:
If the prefix
attribute is missing, or is empty, then the help provider will be registered as a special default help provider. It will be used to produce help for help topic IDs that cannot be matched with any other help provider. Only one default help provider is permitted.
<help-provider-class>
: Create as a child element to the <help-provider>
element.
If you are using a resource bundle, enter the value as oracle.adf.view.rich.help.ResourceBundleHelpProvider
.
If you are using an XLIFF file, enter the value as oracle.adf.view.rich.help.ELHelpProvider
.
If you are using a managed bean or external URL provider, enter the fully qualified class path.
Note:
For external URL help, the provider class should reflect the class that your provider extended.
<property>
: Create as a child element to the <help-provider>
element. The property defines the actual help source.
<property-name>
: Create as a child element to the <property>
element, and enter a name for the source.
<value>
: Create as a child element to the <property>
element. and enter the fully qualified class name of the helper. For example, the qualified class name of the resource bundle used in the ADF Faces demo application is oracle.adfdemo.view.resource.DemoResources
.
If you are using a resource bundle, enter the fully qualified class name of the resource bundle. For example, the qualified class name of the resource bundle used in the ADF Faces demo application is oracle.adfdemo.view.resource.DemoResources
.
If you are using an XLIFF file, enter an EL expression that resolves to the XLIFF file, wrapped in the adfBundle
EL function, for example, #{adfBundle['project1xliff.view.Project1XliffBundle']}
.
If you are using a managed bean, enter an EL expression that resolves to the help map on the managed bean.
If your are using external URL help, enter the fully qualified class name of the provider class you created.
Example 19-7 shows a resource bundle registered in the adf-settings.xml
file.
Example 19-7 Registering a Resource Bundle as a Help Provider
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings"> <adf-faces-config xmlns="http://xmlns.oracle.com/adf/faces/settings"> <help-provider prefix="HELP_"> <help-provider-class> oracle.adf.view.rich.help.ResourceBundleHelpProvider </help-provider-class> <property> <property-name>baseName</property-name> <value>oracle.adfdemo.view.resource.fileExplorer.helpStrings</value> </property> </help-provider> </adf-faces-config> </adf-settings>
Example 19-8 shows an XLIFF file registered in the adf-settings.xml
file.
Example 19-8 Registering an XLIFF File as a Help Provider
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings"> <adf-faces-config xmlns="http://xmlns.oracle.com/adf/faces/settings"> <help-provider prefix="HELP"> <help-provider-class> oracle.adf.view.rich.help.ELHelpProvider </help-provider-class> <property> <property-name>helpSource</property-name> <value>#{adfBundle['project1xliff.view.Project1XliffBundle']}</value> </property> </help-provider> </adf-faces-config> </adf-settings>
Example 19-9 shows a bean registered in the adf-settings.xml
file.
Example 19-9 Registering a Managed Bean as a Help Provider
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings"> <adf-faces-config xmlns="http://xmlns.oracle.com/adf/faces/settings"> <help-provider prefix="HELP_"> <help-provider-class> oracle.adf.view.rich.help.ELHelpProvider </help-provider-class> <property> <property-name>helpSource</property-name> <value>#{helpTranslationMap.helpMap}</value> </property> </help-provider> </adf-faces-config> </adf-settings>
Example 19-10 shows the external help provider registered in the adf-settings.xml
file.
Example 19-10 Registering an External URL Help Provider
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings"> <adf-faces-config xmlns="http://xmlns.oracle.com/adf/faces/settings"> <help-provider prefix="HELP_"> <help-provider-class> oracle.adf.view.rich.help.ResourceBundleHelpProvider </help-provider-class> <property> <property-name>baseName</property-name> <value>oracle.adfdemo.view.resource.DemoHelp</value> </property> </help-provider> </adf-faces-config> </adf-settings>
Example 19-11 shows an example of a custom help provider class registered in the adf-settings.xml
file.
Example 19-11 Registering a Help Provider Class
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings"> <adf-faces-config xmlns="http://xmlns.oracle.com/adf/faces/settings"> <help-provider prefix="MYAPP"> <help-provider-class> oracle.adfdemo.view.webapp.MyHelpProvider </help-provider-class> <property> <property-name>myCustomProperty</property-name> <value>someValue</value> </property> </help-provider> </adf-faces-config> </adf-settings>
Use the HelpTopicId
attribute on components to access and display the help.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
To access help from a component:
In the Structure window, select the component to which you want to add help. For a list of components that support help, see Table 19-1 and Table 19-2.
In the Properties window, expand the Appearance section, and enter a value for the helpTopicId
attribute.
For definition and instruction help, this value should include the prefix to access the correct help provider and the topic name. It should not include the help type, as all help types registered with that name will be returned and displayed.
For example:
<af:inputText label="Customer Service E-Mail" helpTopicId="HELP_CUST_SERVICE_EMAIL"/>
This example will return both the definition and instruction help defined in the XLIFF file in Example 19-3.
If you want to provide help for a component that does not support help, you can instead add an outputText
component to display the help text, and then bind that component to the help provider, for example:
<af:outputFormatted value="#{adfFacesContext.helpProvider['HELP_CUST_SERVICE_ EMAIL'].instructions}"/>
This accesses the instruction help text.
If you are using an external URL help, by default, the user clicks a help icon to launch the help window. Instead, you can use JavaScript and a client event listener for a specific component's event to launch the help window.
It may be helpful to have an understanding of how the attributes can affect functionality. For more information, see Section 19.5, "Displaying Help for Components."
To use JavaScript to launch an external help window:
Create a JavaScript function that uses the launchHelp
API to launch a specific URL or page.
Example 19-12 shows the launchHelp
function used to launch the helpClient.jspx
.
In the ADF Faces page, drag and drop the component whose client event will cause the launchHelp
function to be called. You must set the clientId
on this component to true
.
In the Components window, from the Operations panel, drag and drop a Client Listener as a child to the component created in Step 2. Configure the clientListener
to invoke the function created in Step 1. For more information about using the clientListener
tag, see Section 4.4, "Listening for Client Events."
Example 19-13 shows the code used to assign the click
event of button
component to launch the helpClient.jspx
page.
Example 19-13 Page Code Used to Launch an External Help Window
<af:toolbar id="tb1"> <af:button text="Launch help window" id="ctb1" icon="/images/happy_computer.gif"> <af:clientListener method="launchHelp" type="click"/> </af:button> </af:toolbar> <af:resource type="javascript"> function launchHelp(event) { AdfPage.PAGE.launchHelpWindow("helpClient.jspx"); } </af:resource>
When you add help messages to input components that may already display messages for validation and conversion, ADF Faces displays the messages in the following order within the note window:
Validation and conversion error messages.
Validation and conversion hints.
For input and select components only, Instruction help. For panelHeader
components, Instruction help is always displayed below the header.
Value for shortDesc
attribute.
Figure 19-31 shows an inputDate
component that contains a converter, instruction help, and a tip message.