我觉得这是一个非常容易解决的问题,但我很难过。我整天都在寻找,但我的代码似乎与工作示例的代码相匹配。我正在使用 Struts+SpringMVC+Hibernate,并且正在用 jQuery 标记替换我所有的 dojo 标记。jQuery 下拉菜单没有调用相关的操作。
以下是相关代码:
Struts.xml
<action name="getListOfCities" class="cityActions">
<result type="json">
<param name="root">cities</param>
</result>
</action>
页面.jsp
<s:url id="cityList" action="getListOfCities"/>
<sj:autocompleter name="cities" href="%{cityList}" list="cities" selectBox="true"/>
CityAction.java
public class CityActions implements ModelDriven<CityVO> {
CityService cityService;
private Map<String, String> cities = new HashMap<String, String>();
CityVO city = new CityVO();
public void setCityService(CityService cityService) {
this.cityService = cityService;
}
public CityVO getModel(){
return city;
}
public String execute() {
return Action.SUCCESS;
}
public String addCity(){
try{
cityService.addCity(city);
return "SUCCESS";}
catch(Exception e){
return "ERROR";
}catch(Throwable t){
return "ERROR";
}
}
public Map<String, String> getCities() {
List<CityVO> cityList = cityService.listCities();
Iterator<CityVO> iterator = cityList.iterator();
while (iterator.hasNext()) {
CityVO fac = iterator.next();
cities.put(fac.getCityName(), Integer.toString(fac.getCityId()));
}
return cities;
}
下拉菜单显示但未填充。这是我之前的工作正常:
<s:url id="cityList" action="getListOfCities" />
<sx:autocompleter href="%{cityList}" name="cities" keyValue="0" value="---- SELECT ONE-----"/>
有人对此有解决方案吗?我确保添加
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
和内头:
<sj:head jqueryui="true"/>
谢谢。