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>

좋은 웹페이지 즐겨찾기