我编写了一个简单的概念验证应用程序来测试使用 Oracle ADF 的自动完成字段,虽然它主要工作,但该maxSuggestedItems
属性似乎没有任何效果。Oracle 的文档表明,放置 -1 以外的值应该限制返回的值列表,并在底部包含一个“更多...”项,这将导致整个列表被返回。相反,总是返回整个列表。
这是我必须手动实现的吗?如果是这样,一种方法将如何解决?
JSFF 页面中包含以下代码:
<af:inputText label="Accessories:" id="it4">
<af:autoSuggestBehavior suggestItems="#{accessorySuggest.onAccessorySuggest}"
maxSuggestedItems="5"/>
</af:inputText>
返回建议值(当然都是硬编码)的方法如下:
private static final String[] accessories =
{ "Alloy Wheel", "All-Weather Cargo/Trunk Mat", "All-Weather Floor Mats",
"Audio Unit - Base", "Audio Unit - Premium", "Auto-Dimming Mirror",
"Bluetooth", "Body Side Moldings", "Capert Floor Mats - Premium",
"Car Cover", "Cargo Hooks", "Cargo Liner", "Suggestion 1",
"Suggestion 2", "Suggestion 3", "Suggestion 4", "Suggestion 5",
"Suggestion 6", "Suggestion 7", "Suggestion 8", "Suggestion 9",
"Suggestion 10", "Suggestion 11", "Suggestion 12", "Suggestion 13",
"Suggestion 14", "Suggestion 15", "Suggestion 16", "Suggestion 17",
"Suggestion 18", "Suggestion 19", "Suggestion 20", "Suggestion 21",
"Suggestion 22", "Suggestion 23", "Suggestion 24", "Suggestion 25",
"Suggestion 26", "Suggestion 27", "Suggestion 28", "Suggestion 29",
"Suggestion 30" };
public List onAccessorySuggest(FacesContext context,
AutoSuggestUIHints hints) {
ArrayList<SelectItem> suggestItems = new ArrayList<SelectItem>();
String submittedValue = hints.getSubmittedValue();
//don't return anything until the user has entered at least 3 characters
if(hints.getSubmittedValue().length() < 3) {
return suggestItems;
}
for (String s : accessories) {
if (s.toUpperCase().startsWith(submittedValue.toUpperCase())) {
suggestItems.add(new SelectItem(s));
}
}
return suggestItems;
}