js內容:
/**通過工段ID擷取部門列表*/function getDepartmentListBySectionIdFun(){var sectionId=$("#sectionId").val();var defvalue = $("#departmentId").attr("defvalue");$("#departmentId").empty();$.ajax({type : "post",url : contentPath + "/ajax/getDepartmentListBySectionId.do",data : {sectionId : sectionId},async : false,dataType : "json",success : function(data) {if (data) {var arr=eval(data);for(var i = 0; i < arr.length; i++) {$("#departmentId").append("<option value = '"+arr[i].departmentId+"'>"+arr[i].departmentName+"</option>");}if(defvalue){$("#departmentId").find("option[value = '"+defvalue+"']").attr("selected","selected");}}}});showIePHAndIePersons();}
action內容:
package gts.erp.action.ajax;import gts.erp.action.base.ERPProxyAction;import java.io.PrintWriter;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.oletech.triangle.component.CellBean;import com.oletech.triangle.component.FormBean;import com.oletech.triangle.utils.TriangleUIHelper;/** * * 通過工段ID擷取部門列表 * @author ole * */public class GetDepartmentListBySectionIdAction extends ERPProxyAction {@Overrideprotected ActionForward doExecute(FormBean parameterFB, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {FormBean formBean = this.getERPServiceDelegation().getMasterProductionScheduleService().getDepartmentBySection(parameterFB);JSONArray jsonArray = new JSONArray();for (int i = 0; i < formBean.size(); i++) {CellBean cellBean = formBean.get(i);JSONObject jsonObject = new JSONObject();jsonObject.put("departmentId", cellBean.getKey());jsonObject.put("departmentName", TriangleUIHelper.getMessageResources(request, cellBean.getValue()));jsonArray.add(jsonObject);}PrintWriter pw = response.getWriter();pw.print(jsonArray);pw.flush();return null;}}
impl內容:
/** * 根據工段查詢部門 * @author zhuyz * @date 2016年11月19日17:45:16 * @param dataBean * FormBean => key : "parameterFB" * CellBean key : sectionId * @return FormBean * FormBean Key: errorMsg * TableBean => key : "TN_DEPARTMENT" * CellBean key : CN_ID,CN_NAME.......... * TableBean => key : "TN_DEPARTMENT_IESETUP" * CellBean key : CN_ID,CR_DEPARTMENT_ID...... */public FormBean getDepartmentBySection(FormBean formBean) {String sectionId = formBean.getCellBeanValue("sectionId");FormBean returnFB = new FormBean();try {if (StringUtils.isNotEmpty(sectionId)) {CondSetBean csb = new CondSetBeanJustAnd();csb.addCondBean(new CondBeanEqual("CR_SECTION_ID", sectionId));TableBean tableBean = this.baseDAO.queryForTableBean(new ClassPOJO("TN_DEPARTMENT_IESETUP"), csb);CondSetBean csbDepartment = new CondSetBeanJustAnd();CondBeanIn cbiDepartment = new CondBeanIn(TriangleDefinition.COLUMN_NAME_CN_ID);for (int i = 0; i < tableBean.size(); i++) {cbiDepartment.addValue(tableBean.get(i).getCellBeanValue("CR_DEPARTMENT_ID"));}if (cbiDepartment.size() > 0) {csbDepartment.addCondBean(cbiDepartment);TableBean departmentTB = this.baseDAO.queryForTableBean(new ClassPOJO("TN_DEPARTMENT"), csbDepartment);for (int i = 0; i < departmentTB.size(); i++) {RowBean rowBean = departmentTB.get(i);returnFB.addCellBean(new CellBean(rowBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_ID), rowBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_NAME)));}}}} catch (Exception e) {TriangleBLHelper.printExceptionLog(log, e);e.printStackTrace();throw new RuntimeException("**** Run time Exception。****");}return returnFB;}