<sj:select>不呼吁采取行动
我觉得这是一个非常简单的解决方案,但我很难过.我一整天都在四处搜索,但我的代码似乎与工作示例的代码相匹配.我正在使用 Struts+SpringMVC+Hibernate,我正在用 jQuery 标签替换我所有的 dojo 标签.jQuery 下拉列表未调用关联的操作.
I feel this is a really easy fix but I'm stumped. I've been searching around all day but my code seems to match that of working examples. I'm using Struts+SpringMVC+Hibernate and I'm in the process of replacing all my dojo tags with jQuery tags. The jQuery dropdown is not calling the associated action.
相关代码如下:
Struts.xml
<action name="getListOfCities" class="cityActions">
<result type="json">
<param name="root">cities</param>
</result>
</action>
Page.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;
}
下拉菜单显示但未填充.这是我之前的工作正常:
The dropdown menu shows up but is unpopulated. This is what I had before which worked fine:
<s:url id="cityList" action="getListOfCities" />
<sx:autocompleter href="%{cityList}" name="cities" keyValue="0" value="---- SELECT ONE-----"/>
有没有人有办法解决这个问题?我已经确定添加
Does anyone have a solution to this? I've made sure to add
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
和内部头部:
<sj:head jqueryui="true"/>
谢谢.
(评论太长.拼凑了与您的片段类似的部分版本.)
(Too long for comment. Cobbled together a partial version of something similar to your snippets.)
主要问题是您的结果将 root
设置为 cities
,这意味着返回的 JSON 没有 cities
键,因此自动完成的 list
属性不知道从哪里获取其数据.
The primary issue is that your result sets root
to cities
, meaning the returned JSON has no cities
key, so the autocomplete's list
attribute doesn't know where to get its data.
也就是说:这个版本中的 selectBox
功能有一些时髦的东西;当我删除该属性时,我会在键入时看到数据,将其设置为 true,我什么也得不到.
That said: there is something funky with the selectBox
functionality in this version; when I remove that attribute I see data when I type, with it set to true, I get nothing.
然而,我没有看到选择过滤,这意味着即使它正确突出显示匹配字符,也不会删除不匹配的条目;我相信他们应该是.
I don't, however, see selection filtering, meaning that even though it's correctly highlighting matching characters, non-matching entries aren't being removed; I believe they should be.
无关,但为什么要费心从 VO 创建地图呢?除非我有正当理由(例如,CityVO
太大或包含敏感信息),否则只需使用 listKey
和 listValue
属性并使用服务已经返回.
Unrelated, but why bother creating a map from the VOs? Unless I had a decent reason (e.g., CityVO
is too big or contains sensitive info) just use the listKey
and listValue
attributes and use what the service already returns.