带选择框的Struts2 jQuery Autocompleter
我已经为我的Struts 2应用程序使用了Struts2 jQuery autocompleter
器。
这是我的代码:
JSP:
Struts.xml
:
行动类:
public String populate() throws Exception { itemList = new ArrayList(); itemList.add(new ListValue("Php", "Php")); itemList.add(new ListValue("Java", "Java")); itemList.add(new ListValue("Mysl", "Mysl")); return SUCCESS; } //getter setter for itemList
清单类别:
public class ListValue { private String id; private String name; public ListValue(String id, String name) { this.id = id; this.name = name; } //getter setter methods
但是这个Struts2 jQuery autocompleter
器无法正常工作。 它不会填充任何值。
做这个
而不是这个 :
并确保从行动类返回列表。 要检查这一点,请使用IDE调试器或System.out.print等。
ex... ------------- ------------ itemList.add(new ListValue("Mysl", "Mysl") ); System.out.println("Size of my list="+itemList.size()); return SUCCESS; }
此外,您还应该在动作类中定义getter和setter
private List itemList; public List getItemList() { return itemList; } public void setItemList(List itemList) { this.itemList = itemList; }
这是错的:
您正在使用Map提供自动完成器,而不是使用自己构建的自定义对象。
HashMap没有任何name
或id
字段,而是具有key
s和value
s字段。
首先更改它,看看它是否有效:
您输入了未引用的错误属性。
应该
使用列表项bean类
public class ListValue { private String id; private String name; ... } public String populate() throws Exception { itemList.add(new ListValue("Php", "Php")); itemList.add(new ListValue("Java","Java") ); itemList.add(new ListValue("Mysl", "Mysl") ); return SUCCESS; }
假设已添加构造函数和mutator。