为此目的有一个内置标签。
用户在文本框中输入一个字符,以输入的字符开头的字符串应该以列表的形式显示。从列表中选择的项目应填充在文本框中。
PS:示例和演示可用显示包含输入字符的字符串。但我只想显示以输入字符开头的那些字符串。
为此目的有一个内置标签。
用户在文本框中输入一个字符,以输入的字符开头的字符串应该以列表的形式显示。从列表中选择的项目应填充在文本框中。
PS:示例和演示可用显示包含输入字符的字符串。但我只想显示以输入字符开头的那些字符串。
A way to do that is shown in the wiki page of the pluguin where it says: Autocompleter that handle a JSON Result. Yo just set that code in your jsp, and then you implement something like this in your action:
private static String[] staticLanguages = { ...a list... };
private String term;
private String[] languages = Autocompleter.staticLanguages;
public String execute() throws Exception {
if (term != null && term.length() > 1)
{
ArrayList<String> tmp = new ArrayList<String>();
for (int i = 0; i < staticLanguages.length; i++)
{
if (StringUtils.contains(staticLanguages[i].toLowerCase(), term.toLowerCase()))
{
tmp.add(staticLanguages[i]);
}
}
languages = tmp.toArray(new String[tmp.size()]);
}
return SUCCESS;
}
Just change StringUtils.contains line and check instead if the begining is the same.
The jsp tag would be:
<sj:autocompleter
name="term"
id="languages"
href="%{remoteurl}"
delay="50"
loadMinimumCount="2"
/>
I think this should work. Just take a look at the example code in the wiki and try it out.
我使用 Struts2 和 Jquery 制作了自己的自动完成实用程序,它们从 oracle 读取数据并显示建议列表,您可以根据您的要求进行相应更改。请从这里下载代码http://javaant.com/dynamic-autocomplete-using-jquery-struts2-and-oracle/#.V0RxL5N96Hs