觸動 多項選擇 獲取關聯的值 (ext js jQuery sturs hibernate springside)

1,頁面  標籤代碼

                        <td width="10%" align="right">

處理部門:
</td>
<td width="15%" align="left">
<select name="department" style="width: 133"  οnchange="getPerson(this)" id="department_id">
<option value="" >
--請選擇--
</option>
<OPTION VALUE="質量管理部" <%="質量管理部".equals(department) ? "selected" : ""%>>
質量管理部
</OPTION>
<!-- 
<OPTION VALUE="質量管理中心" <%="質量管理中心".equals(department) ? "selected" : ""%>>
質量管理中心
</OPTION>
-->
</select>
</td>
<td width="10%" align="right">
處理人:
</td>
<td width="15%" align="left">
<select id="person_id" style="width: 90" name="person">
<option style="color: gray" value="${person}" >
--請選擇--
</option>

</select>


2,js代碼

                function getPerson(person1){
   var department = document.getElementById("department_id").value;   
   //獲取觸發關聯 的id
var person = document.getElementById("person_id").value;
//獲取被動觸發的關聯id
var sel = dwr.util.getValue("person_id");
Ext.Ajax.request( {
//異步請求Ajax 的對象request
url : '${ctx}/complaints/satisfiedchart!qureyPerson.action',
//請求的路徑
params : {  
//參數 要與 對應的 action在的參數對應
department : department
},
//判斷結果
success : function(response) {
//轉換成js
var json = Ext.util.JSON.decode(response.responseText);
if (json.success) {
//獲取數據
var data = json.cmList;
//判斷數據
if ("" == data) {
document.getElementById("department_id").focus();
//第一次加載頁面爲空顯示   --請選擇--
return;
// $("#person_id").empty();
} else {
$("#person_id").empty();
//對獲取到的數據進行迭代
for ( var i = 0; i < data.length; i++) {
var id = data[i];
var name = data[i];
$("#person_id").append(
"<option value='" + id + "'>" + name + "</option>");
}
if(person!=""){
////加載頁面後爲空顯示   當前的處理人
document.getElementById("person_id").value=person;
}
//將上次的 選擇清空 並賦值
dwr.util.removeAllOptions('department');
dwr.util.addOptions('department', data);
}
}
}
} )
}

3.Action 代碼

                         //通過處理部門得到具體的處理人
//定義ext傳過來的參數對應
private String department;
public void qureyPerson() throws Exception{
//new一個響應的對象
HttpServletResponse response = ServletActionContext.getResponse();
//參數賦值
String cp_department = department;
//定義sql
String sql1=" select name from t_users t where t.departmentcomposename ="+"'"+cp_department+"'";
//查詢數據
List<Users>  jsrListName = (List)complaintsManager.findBySQL(sql1);
response.setContentType("text/javascript"); //後臺控制的代碼
//new 一個 writer 對象
   PrintWriter writer = response.getWriter();
   //將得到的list集合轉爲JSON對象傳給前臺處理
   JSONArray j = JSONArray.fromObject(jsrListName);
   //調用有值 返回給ext
   writer.println("{'success':true,'cmList':"+j.toString()+"}");    
}

     

3.1,hibernate 方法

           //報表查詢方法
public List<Object> findBySQL(final String sql) {
return complaintsdao.findBySQL(sql);
}

             public List<Object> findBySQL(final String sql) {
  Session session = this.getSession();
  List<Object> catNameList = null;
  try {
    catNameList = session.createSQLQuery(sql).list();
   return catNameList ;
  }catch(Exception ex)
  {
  ex.printStackTrace();
  } 
return catNameList;

            public Session getSession() {
return sessionFactory.getCurrentSession();
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章