< SJ:选择>没有调用动作 [英] <sj:select> not calling action
问题描述
我正在使用Struts + SpringMVC + Hibernate,我正在用jQuery标签替换所有的dojo标签。 jQuery下拉菜单不会调用相关联的操作。
以下是相关代码:
Struts .xml
< action name =getListOfCitiesclass =cityActions>
< result type =json>
< param name =root> cities< / param>
< / result>
< / action>
Page.jsp
< s:url id =cityListaction =getListOfCities/>
< sj:autocompleter name =citieshref =%{cityList}list =citiesselectBox =true/>
CityAction.java
public class CityActions实现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);
returnSUCCESS;}
catch(异常e){
returnERROR;
} catch(Throwable t){
returnERROR;
}
}
public Map< String,String> getCities(){
列表< CityVO> cityList = cityService.listCities();
迭代器< CityVO> iterator = cityList.iterator();
while(iterator.hasNext()){
CityVO fac = iterator.next();
cities.put(fac.getCityName(),Integer.toString(fac.getCityId()));
}
返回城市;
}
下拉菜单显示但未填充。这是我之前工作正常的:
< s:url id =cityListaction =getListOfCities/ >
< sx:autocompleter href =%{cityList}name =citieskeyValue =0value =---- SELECT ONE -----/>
有没有人有解决方案?我确定添加
<%@ taglib prefix =sjuri =/ struts-jquery-tags %>
和内部头:
< sj:head jqueryui =true/>
谢谢。
(太长的评论,将一些类似于您的片段的部分版本混合在一起。)
主要问题是您的结果集 root
到城市
,意味着返回的JSON没有城市
所以autocomplete的列表
属性不知道从哪里获取它的数据。
说:是这个版本中的 selectBox
功能,当我删除该属性时,我看到数据,当我键入,它设置为true,我什么也没有。
然而,我不知道选择过滤,这意味着即使正确突出显示匹配的字符,也不会删除不匹配的条目;我相信他们应该是。
无关,但为什么要从VOs创建地图?除非我有一个体面的原因(例如, CityVO
太大或包含敏感信息)只需使用 listKey
和 listValue
属性,并使用服务已经返回的内容。
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.
Here is the relevant code:
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"%>
and inside head:
<sj:head jqueryui="true"/>
Thanks.
(Too long for comment. Cobbled together a partial version of something similar to your snippets.)
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.
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.
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.
这篇关于< SJ:选择>没有调用动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!