Exemple #1
0
  public int doStartTag() throws JspException {
    if (Strings.isBlank(id)) return SKIP_BODY;
    StringBuilder strb = new StringBuilder();
    if (LOGIC_TRUE.equals(readonly)) {
      if (Strings.isBlank(value)) return SKIP_BODY;
      String[] values = value.trim().split(",");

      StringBuilder rstr = new StringBuilder();
      String temp = "";
      if (Strings.isBlank(dictCode)) {
        JdbcTemplate jdbcTemplate =
            (JdbcTemplate) SpringContextHolder.getApplicationContext().getBean("jdbcTemplate");
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);

        if (list != null && list.size() > 0) {
          for (String val : values) {
            if (Strings.isBlank(val)) continue;
            for (Map<String, Object> map : list) {
              if (map.get(sqlValueKey) != null && map.get(sqlValueKey).toString().equals(val)) {
                rstr.append(",")
                    .append(map.get(sqlLableKey) == null ? "" : map.get(sqlLableKey).toString());
              }
            }
          }
        }
      } else {
        for (String val : values) {
          if (Strings.isNotBlank(temp = DictCacheService.getThis().getItemLabel(dictCode, val))) {
            rstr.append(",").append(temp.trim());
          }
        }
      }
      if (rstr.length() > 1) {
        temp = rstr.substring(1);
      } else {
        temp = rstr.toString();
      }
      strb.append(temp)
          .append(
              "<input type='hidden' id='" + id + "' name='" + id + "' value='" + value + "' />");
    } else {
      strb.append(this.bulidHtml())
          .append("\n<script type='text/javascript'>\n")
          .append(this.bulidTreeSetting())
          .append("var zNodes_" + id + " = ")
          .append(this.bulidNodes())
          .append(";\n\n\n")
          .append(this.bulidBeforeCheck())
          .append(this.bulidOnCheck())
          .append(this.bulidMenuDisplay())
          .append(this.bulidOnReady())
          .append(this.bulidClearFun());
      if (LOGIC_TRUE.equals(labelCheck)) {
        strb.append(this.bulidOnClick());
      }
      strb.append("</script>\n\n");
    }
    try {
      pageContext.getOut().print(strb.toString());
    } catch (java.io.IOException e) {
      e.printStackTrace();
      throw new JspTagException(e.getMessage());
    }

    return SKIP_BODY;
  }
Exemple #2
0
 private String bulidNodes() {
   List<Map<String, Object>> rsList = new ArrayList<Map<String, Object>>();
   Map<String, Object> item = new HashMap<String, Object>();
   item.put("id", this.virtualRootId);
   item.put("pId", "");
   item.put("name", this.virtualRootLabel);
   item.put("isParent", true);
   item.put("open", true);
   rsList.add(item);
   if (Strings.isBlank(dictCode)) {
     if (Strings.isBlank(sql)) return "[]";
     JdbcTemplate jdbcTemplate =
         (JdbcTemplate) SpringContextHolder.getApplicationContext().getBean("jdbcTemplate");
     List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
     if (list != null && list.size() > 0) {
       for (Map<String, Object> map : list) {
         if (Strings.isNotBlank(valDefault)) {
           String[] vals = valDefault.split(",");
           for (String s : vals) {
             if (map.get(sqlValueKey) != null
                 && map.get(sqlValueKey).toString().trim().equals(s.trim())) {
               item = new HashMap<String, Object>();
               item.put("id", map.get(sqlValueKey));
               item.put("pId", this.virtualRootId);
               item.put("name", map.get(sqlLableKey));
               rsList.add(item);
             }
           }
         } else {
           item = new HashMap<String, Object>();
           item.put("id", map.get(sqlValueKey));
           item.put("pId", this.virtualRootId);
           item.put("name", map.get(sqlLableKey));
           rsList.add(item);
         }
       }
     }
   } else {
     List<DictItem> list = DictCacheService.getThis().getItemsByDictCode(dictCode.trim());
     if (list != null && list.size() > 0) {
       for (DictItem dictItem : list) {
         if (dictItem != null && SysConstant.STATUS_NORMAL == dictItem.getStatus()) {
           if (Strings.isNotBlank(valDefault)) {
             String[] vals = valDefault.split(",");
             for (String s : vals) {
               if (dictItem.getItemCode() != null
                   && dictItem.getItemCode().toString().trim().equals(s.trim())) {
                 item = new HashMap<String, Object>();
                 item.put("id", dictItem.getItemCode());
                 item.put("pId", this.virtualRootId);
                 item.put("name", dictItem.getItemName());
                 rsList.add(item);
               }
             }
           } else {
             item = new HashMap<String, Object>();
             item.put("id", dictItem.getItemCode());
             item.put("pId", this.virtualRootId);
             item.put("name", dictItem.getItemName());
             rsList.add(item);
           }
         }
       }
     }
   }
   return JSON.toJSONString(rsList);
 }