gpt4 book ai didi

java - 带选择框的 Struts2 jQuery 自动完成器

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:09 24 4
gpt4 key购买 nike

我为我的 Struts 2 应用程序使用了 Struts2 jQuery autocompleter

这是我的代码:

JSP:

 <s:form id="frm_demo" theme="simple" action="ManagersAutoCompleter1">
<s:url var="remoteurl" action="test" />
<sj:autocompleter href="%{remoteurl}" id="echo3" name="echo"
list="itemList" listKey="id" listValue="name" emptyOption="true"
headerKey="-1" headerValue="Please Select a Language" selectBox="true" />

<s:submit value="submit" />
</s:form>

Struts.xml:

<action name="test" class="test.TestAction" method="populate">
<result type="json">
</result>
</action>

Action 类:

 public String populate() throws Exception {

itemList = new ArrayList<ListValue>();
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 不工作。它不填充任何值。

最佳答案

做这个

<s:url id="remoteurl" action="test"/>
<sj:select
id="customersjsonlstid"
name="echo"
label="Handle a List"
href="%{remoteurl}"
list="itemList"
listValue="name"
listKey="id"
autocomplete="true"
loadMinimumCount="2"
id="echo3"/>

代替这个:

<sj:autocompleter href="%{remoteurl}" id="echo3" name="echo"
list="itemList" listKey="id" listValue="name" emptyOption="true"
headerKey="-1" headerValue="Please Select a Language" selectBox="true" />

并确保您从操作类中返回列表。要检查这一点,请使用您的 IDE 调试器或 System.out.print 等。

ex...


-------------
------------
itemList.add(new ListValue("Mysl", "Mysl") );
System.out.println("Size of my list="+itemList.size());
return SUCCESS;
}

你还应该在你的 Action 类中定义 getter 和 setter

private List itemList; 
public List getItemList() {
return itemList;
}

public void setItemList(List itemList) {
this.itemList = itemList;
}

关于java - 带选择框的 Struts2 jQuery 自动完成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14153943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com