Дополнительная настройка > Business Logic Customization > Options and Variants > Configuring Auto-Suggest Results for Options and Choices
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. The following can be customized:
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.
Any of the following criteria can be used for searching:
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 the 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 can be used 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.
* 
SuggestResult contains valueOf (String display_text, String additional_text, String value_text) used to set the display text visible on the user interface. 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 by adding it to the list of services present in typedServices.properties. The custom suggestable class must also be registered 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, to search 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 the addSuggestions method is called from the custom getFormatedSuggestions method.
3. Register the suggestable class by adding it to the list of services present in the typedServices.properties. The custom suggestable class must be registered in an xconf file and then propagated 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 provides display results for named option and choices starting with the letter c), or to search or display either soft types or soft attributes, a custom Suggest class can be created as mentioned in the above sections, and the constructSuggestions (SuggestParms suggestParms) method can be overwritten, where the custom logic is added for changing the searchTerm or fetching and displaying the soft types or soft attributes.
Было ли это полезно?