⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oldfunctions.jsp

📁 国外的一套开源CRM
💻 JSP
📖 第 1 页 / 共 2 页
字号:
<!-- [oldFunctions.jsp] Begin -->
<%!

    /*
    *  Takes a string in the following format:
    *    formatString
    *  Where the first letter is lowercase, and
    *  subsequent unique words begin with an upper case.
    *  The function will convert a java string to a regular
    *  string in title case format.
    */
    String formatJavaString(String s){
      char ca[] = s.toCharArray();
      StringBuffer sb = new StringBuffer();
      int previous = 0;
      for(int i=0;i<ca.length;i++){
        if(i==s.length()-1){
          sb.append(s.substring(previous, previous+1).toUpperCase());
          sb.append(s.substring(previous+1, s.length()));
        }
        if(Character.isUpperCase(ca[i])){
          sb.append(s.substring(previous, previous+1).toUpperCase());
          sb.append(s.substring(previous+1, i));
          sb.append(" ");
          previous = i;
        }
      }
      return sb.toString();
    }


  /**
   Properties must include:
    NAME-name of the select used in name-value form submit.
    VALUE_FIELD-the value sent in form submit.
    DISPLAY_FIELD-the field used in the display of the drop-down. use a
    Properties can include:
    Selected-The value to test for, and set selected on the drop-down
    EMPTY_FIRST: if just a blank field use "{field display vaalue}, else if value supplied use "{field value}, {field value display name}"
  */
  String buildDropDown(List l, Map properties){
   StringBuffer returnString = new StringBuffer();
   GenericValue genericValue = null;
   Iterator i = l.iterator();
   String selected = ((String)(properties.get("SELECTED") != null ? properties.get("SELECTED") : ""));
   String display =  ((String)(properties.get("DISPLAY_FIELD") != null ? properties.get("DISPLAY_FIELD") : ""));
   String selectJavaScript = ((String)(properties.get("SELECT_JAVASCRIPT") != null ? properties.get("SELECT_JAVASCRIPT") : ""));
   returnString.append("<select name=\"" + properties.get("NAME") + "\" " + selectJavaScript + " >");
   if(properties.get("EMPTY_FIRST") != null) {
    String empty = (String)properties.get("EMPTY_FIRST");
    if(empty.indexOf(",") != -1){
      StringTokenizer tok = new StringTokenizer(empty, ",");
      returnString.append("<option value=\"" + ((String)tok.nextElement()).trim() + "\">" + ((String)tok.nextElement()).trim());
    } else {
      returnString.append("<option value=\"\">" + empty);
    }
   }
try{
   while(i.hasNext()){
     genericValue = (GenericValue)i.next();
     returnString.append("<option value=\"" + String.valueOf(genericValue.get((String)properties.get("VALUE_FIELD"))) + "\"");
     if(String.valueOf(genericValue.get((String)properties.get("VALUE_FIELD"))).equals(selected)){
      returnString.append(" SELECTED ");
     }
     returnString.append(" >");
     if(display.indexOf(",") != -1){
       StringTokenizer tok = new StringTokenizer(display, ",");
       while(tok.hasMoreElements()){
         String elem = (String)tok.nextElement();
         returnString.append(String.valueOf(genericValue.get(elem.trim())));
         returnString.append(" ");
       }
     } else {
       returnString.append(genericValue.get(display));
     }
   }
} catch (Exception e){ e.printStackTrace(); }
   returnString.append("</select>");
   return returnString.toString();
  }

  String buildStringDropDown(List l, Map properties){
   StringBuffer returnString = new StringBuffer();
   String value = "";
   Iterator i = l.iterator();
   String selected = ((String)(properties.get("SELECTED") != null ? properties.get("SELECTED") : ""));
   String display =  ((String)(properties.get("DISPLAY_FIELD") != null ? properties.get("DISPLAY_FIELD") : ""));
   String selectJavaScript = ((String)(properties.get("SELECT_JAVASCRIPT") != null ? properties.get("SELECT_JAVASCRIPT") : ""));
   returnString.append("<select name=\"" + properties.get("NAME") + "\" " + selectJavaScript + " >");
   if(properties.get("EMPTY_FIRST") != null) {
    String empty = (String)properties.get("EMPTY_FIRST");
    if(empty.indexOf(",") != -1){
      StringTokenizer tok = new StringTokenizer(empty, ",");
      returnString.append("<option value=\"" + ((String)tok.nextElement()).trim() + "\">" + ((String)tok.nextElement()).trim());
    } else {
      returnString.append("<option value=\"\">" + empty);
    }
   }
   while(i.hasNext()){
     value = (String)i.next();
     returnString.append("<option value=\"" + value + "\"");
     if(value.equals(selected)){
      returnString.append(" SELECTED ");
     }
     returnString.append(" >");
     if(display.indexOf(",") != -1){
       StringTokenizer tok = new StringTokenizer(display, ",");
       while(tok.hasMoreElements()){
         String elem = (String)tok.nextElement();
         returnString.append(value);
         returnString.append(" ");
       }
     } else {
       returnString.append(value);
     }
   }
   returnString.append("</select>");
   return returnString.toString();
  }

  String buildFieldDropDown(Vector fields, String entityName, HashMap properties){
   if(properties == null) properties = new HashMap();
   StringBuffer returnString = new StringBuffer();
   ModelField modelField = null;
   String selected = ((String)(properties.get("SELECTED") != null ? properties.get("SELECTED") : ""));
   returnString.append("<select name=\"" + entityName + "\" >");
   if(properties.get("EMPTY_FIRST") != null) returnString.append("<option value=\"\">" + properties.get("EMPTY_FIRST"));
   for(int i=0;i<fields.size();i++){
     modelField = (ModelField)fields.get(i);
     returnString.append("<option value=\"" + modelField.getName() + "\"");
     if((modelField.getName()).equals(selected)){
      returnString.append(" SELECTED ");
     }
     returnString.append(" >" + formatJavaString(modelField.getName()));
   }
   returnString.append("</select>");
   return returnString.toString();
  }


  /**
  * Checks a List of fields to see if the string
  * that is passed in exists in the vector.  If so,
  * it returns the ModelField for the named field, else
  * it returns null.
  */
  ModelField contains(List v, String s){
    ModelField field;
    for(int i=0; i<v.size();i++){
      field = (ModelField)v.get(i);
      if(field.getName().equals(s))
        return field;
    }
    return null;
  }

  String buildUIFieldDropDown(String sectionName, List fields, String entityName, HashMap properties){
   if(properties == null) properties = new HashMap();
   StringBuffer returnString = new StringBuffer();
   UIFieldInfo fieldInfo = null;
   String selected = ((String)(properties.get("SELECTED") != null ? properties.get("SELECTED") : ""));
   returnString.append("<select name=\"" + entityName + "\" >");
   if(properties.get("EMPTY_FIRST") != null) returnString.append("<option value=\"\">" + properties.get("EMPTY_FIRST"));
   for(int i=0;i<fields.size();i++){
     fieldInfo = (UIFieldInfo)fields.get(i);
     if ( fieldInfo.getIsVisible() && !fieldInfo.getIsReadOnly() )
     {
	    String attrId = UIWebUtility.getHtmlName(sectionName, fieldInfo, 0);
     	String attrName = fieldInfo.getDisplayLabel();
     	returnString.append("<option value=\"" +  attrId + "\"");
     	if(attrName.equals(selected)){
      		returnString.append(" SELECTED ");
     	}
     	returnString.append(" >" + attrName);
     }
   	}
   	returnString.append("</select>");
   	return returnString.toString();
  }

 /**
 * Given a ModelField and a value, this function checks the datatype for the field, and
 * converts the value to the correct datatype.
 */
 GenericValue setCorrectDataType(GenericValue entity, ModelField curField, String value){
    ModelFieldTypeReader modelFieldTypeReader = new ModelFieldTypeReader("mysql");
    ModelFieldType mft = modelFieldTypeReader.getModelFieldType(curField.getType());
    String fieldType = mft.getJavaType();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm a");

    if(fieldType.equals("java.lang.String") || fieldType.equals("String")){
      if ( mft.getType().equals("indicator") )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -