`

用纯javascript写的异步调用js文件xmlcommon.js三

 
阅读更多

后台代码:

1.AjaxUtil.java

package com.tpaic.ruleengine.util;

import java.util.List;

import com.tpaic.ruleengine.domain.DecisionRule;
import com.tpaic.tpfa.app.util.CommonFunctions;
import com.tpaic.tpfa.app.web.util.Builder;

public class AjaxUtil {
 
 public static String buildOptions(List list, String itemName) {
  if(CommonFunctions.isEmpty(list)){
   return "";
  }
  StringBuffer xmldata = new StringBuffer();
  Builder.appendSelectBegin(xmldata, itemName);
  xmldata.append("<options>");
  Builder.appendOptionValue(xmldata, "请选择", "");
  if (list != null && list.size() > 0) {
   for (int i = 0; i < list.size(); i++) {
    DecisionRule obj = (DecisionRule) list.get(i);
    Builder.appendOptionValue(xmldata,obj.getRuleName(), obj.getRuleId());
   }
  }
  xmldata.append("</options>");
  Builder.appendSelectEnd(xmldata, itemName);
  return xmldata.toString();
 }

}
2.Calib6GetDecisionRuleController.java

package com.tpaic.ruleengine.presentation.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import com.tpaic.ruleengine.domain.DecisionRule;
import com.tpaic.ruleengine.util.AjaxUtil;
import com.tpaic.ruleengine.util.Constants;
import com.tpaic.ruleengine.util.ContantsCharater;
import com.tpaic.ruleengine.util.ServiceRequestID;
import com.tpaic.tpfa.app.dto.ActionDTO;
import com.tpaic.tpfa.app.util.CommonFunctions;
import com.tpaic.tpfa.app.util.StringUtil;
import com.tpaic.tpfa.app.web.AbstractViewController;
import com.tpaic.tpfa.app.web.exception.WebException;
import com.tpaic.tpfa.app.web.util.Builder;

public class Calib6GetDecisionRuleController extends AbstractViewController {

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        Map model = new HashMap();
        try {
         String departmentCode = request.getParameter("departmentCode");//机构编码
         StringBuffer xmldata = new StringBuffer();
   Builder.beginXMLRoot(xmldata);
   List list = getList(departmentCode,ContantsCharater.BUSINESS_TYPE_D1);
   xmldata.append(AjaxUtil.buildOptions(list, "calibRuleId"));//规则类型
         Builder.endXMLRoot(xmldata);
   return new ModelAndView(this.getFormView(), "xmldata", xmldata.toString());
        } catch (Exception e) {
            e.printStackTrace();
            model = new HashMap();
            model.put(Constants.ERROR_MSG, e.getMessage());
            model.put(Constants.ERROR_EXCEPTION, StringUtil
                    .getThrowableString(e));
            return new ModelAndView(Constants.ERROR_PAGE, model);
        }
    }
   
 private List getList(String departmentCode,String businessType) throws Exception {
  DecisionRule obj = new DecisionRule();
  if(CommonFunctions.isEmpty(departmentCode)) {
   throw new WebException("机构ID不能为空");
  }
  obj.setDepartmentCode(departmentCode);
  obj.setBusinessType(businessType);
  ActionDTO actionDTO = new ActionDTO();
  actionDTO.setOperationType(Constants.ACTION_METHOD_SEARCH);
  actionDTO.setObject(obj);
  List decisionRuleList = (List) dispatch.dispatchRequest(actionDTO,ServiceRequestID.DECISION_RULE_ACTION);
  return decisionRuleList;
 }
 
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics