Configuring Auto-Suggest Results for Options and Choices
This section describes how to customize the display of search results and criteria used for choice suggestions when creating assigned expressions, conditional rules, or aliases. You can customize the following:
• Display of search results (suggestions)
• Search criteria
• Columns displayed in search results
|
To enable the auto-suggest capability, set the Allow Choice Auto Suggest preference to Yes.
|
You can search using any of the following criteria:
• Choice name
• Choice number
• Option name
• Alias name
You can add additional search and display attributes from fields defined in the choice and option classes using the properties defined in the xconf file. For searching on or displaying soft types and modeled types for option and choices, use the customizations described in this section.
Prerequisite Knowledge
To achieve this objective, you must have an understanding of the following:
• Basic development including JSP, JavaScript, Custom taglibs
• Windchill xconfmanager concepts
Solution Elements
Element
|
Type
|
Description
|
ATOOptionSuggestable
|
Java class
|
Provides suggestions based on the search term. This class determines the logic for fetching the search results from database.
|
*.wt.properties.xconf
|
Properties xconf file
|
Contains the ato.suggest.displayColumns and ato.suggest.searchColumns properties that you can use to specify additional columns (attributes) to be fetched from the database and columns on which the search is based, respectively.
|
*. typedservices.properties.xconf
|
Properties xconf file
|
|
Procedure
Case 1: Changing the Order of Display Text of the Suggest Result Displayed on UI
To change the format of the display text of the suggest results, follow these steps:
1. Create a suggestable class. Customized suggestable class extends the ATOOptionSuggestable class. This class has getFormatedSuggestions(Collection<ChoiceSuggestionBean> suggestBean) method that is used to create displayText, additional text, and value text for the suggest result from the provided ChoiceSuggestionBean. The method internally calls the addSuggestions(String displayText, String additionalText, String valueText) that is then used to encode the displayText, additionalText, and ValueText, and set them to the collection of suggestResult to be passed to the user interface.
It is mandatory to call the addSuggestions method from the getFormatedSuggestions to ensure the suggestions are visible on the user interface.
|
SuggetsResult contains valueOf (String display_text, String additional_text, String value_text) that is used to set the display text visible on the user interfacce. The first argument is the text to be displayed in the drop-down menu. The second argument is any additional text that is displayed as a separate column in the suggest drop-down menu. The third argument is any string that must be copied to the hidden form field associated with the text box, and displayed in the text.
|
2. Register the suggestable class. To register your suggestable class, add it to the list of services present in typedServices.properties. You also need to register your custom suggestable class in an xconf file and propagate into the /codebase/service.properties file using xconfmanager.
<Service context="default" name="com.ptc.core.components.suggest.Suggestable">
<option cardinality="duplicate" selector="optionPicker" requestor="null"
serviceClass="<your_Suggestable>" />
</Service>
Case 2: Changing Search Criteria
To search on additional attributes of choices or options other than the out-of-the-box attributes (Choice Name, Choice Number, Option Name, Alias Name), add the additional attributes through xconf file and propagate it into the codebase/wt.properties using xconfmanager.
For example, to search the choices or options based on the Choice Description attribute, add the following property into your custom xconf file:
<Property name="ato.suggest.searchColumns" multivalued=","
default="Choice.description" overridable="true" />
The attributes to be added must be prefixed by the class name that they belong to. In this example, to search choice description, the attribute added is Choice.description. Similarly, for searching on the basis of option description, add the Option.description attribute.
Case 3: Displaying Additional Attributes on the User Interface
To display additional attributes of choices or options other than the out-of-the-box attributes (Choice Name, Choice Number, Option Name) on the user interface, follow these steps:
1. Override the getFormatedSuggestions(Collection<ChoiceSuggestionBean>suggestBean) by creating a suggestable class that extends the ATOOptionSuggestable class.
2. Create a suggestable class. This customized suggestable class extends the ATOOptionSuggestable class. This class has getFormatedSuggestions(Collection<ChoiceSuggestionBean> suggestBean) method. The ChoiceSuggestionBean contains choice, option, and alias objects, through which you can fetch the additional attributes to be displayed on the user interface.
Example code to display the additional attributes description on the user interface:
@Override
public void getFormatedSuggestions(Collection<ChoiceSuggestionBean>suggestBeans) {
String number = "";
String name = "";
String description = "";
String displayText = "";
String valueText = "";
String additionalText = "";
for (ChoiceSuggestionBean bean : suggestBeans) {
if (bean.getChoice() != null) {
number = bean.getChoice().getNumber();
name = bean.getChoice().getName();
description = bean.getChoice().getDescription();
}
if (bean.getAlias() != null) {
number = bean.getAlias().getNumber();
name = bean.getAlias().getName();
description = bean.getAlias().getDescription();
}
if (bean.getOption() != null) {
additionalText = bean.getOption().getName();
}
displayText = name + "," + number + "," + description;
try {
if (OptionsClientHelper.isNumberBasedDisplayEnabled()) {
valueText = number + name;
} else {
valueText = name + number;
}
} catch (WTException e) {
logger.error(e);
}
addSuggestions(displayText, additionalText, valueText);
}
}
|
Ensure that you have called the addSuggestions method from your getFormatedSuggestions method.
|
3. Register the suggestable class by adding it to the list of services present in the typedServices.properties. You must register the custom suggestable class in an xconf file and propagate it into the /codebase/service.properties file using xconfmanager.
<Service context="default" name="com.ptc.core.components.suggest.Suggestable">
<Option cardinality="duplicate" selector="optionalPicker" requestor="null"
serviceClass="<your_Suggestable> " />
</Service>
Other Customizations
For other customizations such as changing the information triggering the search (for example, typing option.c that will display results for named option and choices starting with the letter c), or searching or displaying soft types or soft attributes, you can create your own Suggest class as mentioned in the above sections, and override the constructSuggestions (SuggestParms suggestParms) method, where you can implement your own logic for changing the searchTerm or fetching and displaying the soft types or soft attributes.