struts2 + extjs 级联

//为站点添加onchange事件
Ext.getCmp('_s_combobox_peSite_siteName').on('change',function(e,id){
getList(id ,'/entity/teaching/electiveManage_ajaxGetTraining.action?siteId='+id , '_s_combobox_peTraining_trainingName');
});
//为培训添加onchange事件
Ext.getCmp('_s_combobox_peTraining_trainingName').on('change',function(e,id){
getList(id ,'/entity/teaching/electiveManage_ajaxGetCourse.action?trainId='+id , '_s_combobox_peTchCourse_courseName');
});
//为站点添加onfocus事件,清除培训、课程下拉框中的值
Ext.getCmp('_s_combobox_peSite_siteName').on('focus',function(e,id){
_s_combobox_peTraining_trainingName.clearValue();
_s_combobox_peTchCourse_courseName.clearValue();
});
//为培训添加onfocus事件,清除课程下拉框中的值
Ext.getCmp('_s_combobox_peTraining_trainingName').on('focus',function(e,id){
Ext.getCmp('_s_combobox_peTchCourse_courseName').clearValue();
});
function getList(id,url,target){
Ext.Ajax.request({
url:url,
method:'GET',
disableCaching:true,
callback:function(option,success,response){
if(success){
var recordsData = eval(response.responseText);
if(target=='_s_combobox_peTraining_trainingName'){
_s_combobox_peTraining_trainingName.store.removeAll();
_s_combobox_peTchCourse_courseName.store.removeAll();
_s_combobox_peTraining_trainingName.store.loadData(recordsData);
}else if(target='_s_combobox_peTchCourse_courseName'){
_s_combobox_peTchCourse_courseName.store.removeAll();
_s_combobox_peTchCourse_courseName.store.loadData(recordsData);
}
}
}
});
}

Action里面的方法

//站点 ----级联查询  课程
public String ajaxGetTraining(){
DetachedCriteria dc = DetachedCriteria.forClass(PeTraining.class);
dc.createCriteria("peSite", "peSite")
.add(Restrictions.eq("id", this.getSiteId()));
dc.addOrder(Order.asc("name"));
try {
trainList = this.getGeneralService().getList(dc);
} catch (EntityException e) {
e.printStackTrace();
}
StringBuffer temp =new StringBuffer();
temp.append("[");
for (int i = 0; i < trainList.size(); i++) {
temp.append("['");
temp.append(trainList.get(i).getId());
temp.append("','");
temp.append(trainList.get(i).getName());
temp.append("']");
if(i!=trainList.size()-1){
temp.append(",");
}
}
temp.append("]");
this.setAjaxResult(temp.toString());
return "ajaxcheck";
}
//站点 ----级联查询  培训
public String ajaxGetCourse(){
DetachedCriteria dc = DetachedCriteria.forClass(PrTrainingCourse.class);
dc.createCriteria("peTraining","peTraining")
.add(Restrictions.eq("id", this.getTrainId()));
dc.createCriteria("peTchCourse", "peTchCourse").addOrder(Order.desc("pubTime"));
try {
courseList = this.getGeneralService().getList(dc);
} catch (EntityException e) {
e.printStackTrace();
}
StringBuffer temp =new StringBuffer();
temp.append("[");
for (int i = 0; i < courseList.size(); i++) {
temp.append("['");
temp.append(courseList.get(i).getPeTchCourse().getId());
temp.append("','");
temp.append(courseList.get(i).getPeTchCourse().getName());
temp.append("']");
if(i!=courseList.size()-1){
temp.append(",");
}
}
temp.append("]");
this.setAjaxResult(temp.toString());
return "ajaxcheck";
}

struts.xml配置

<result name="ajaxcheck">/WEB-INF/template/entity/pub/ajaxcheck.jsp</result>

ajaxcheck.jsp内容

<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld" %>
<% response.setHeader("expires", "0"); %>
<s:if test='ajaxResult!=null'><s:property value="ajaxResult" escape="false"/></s:if><s:else><s:property value="#request.ajaxResult" escape="false"/></s:else>

 

你可能感兴趣的:(struts2,ExtJs,load,extjs级联)