本文实例为大家分享了form表单回写技术,供大家参考,具体内容如下
回写支持的java拼js的方法:
public static String writeBackMapToForm(Map mRequest) {
return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm");
}
public static String writeBackMapToForm(Map mRequest, String[] ignoreName, String jsFunctionName) {
mRequest.remove("checkbox_template"); //不回写列表中checkbox的值
StringBuffer rtValue = new StringBuffer();
rtValue.append(" var mForm = new Object();n");
rtValue.append(" var indexArray = new Array();n");
rtValue.append(" function writeBackMapToForm() {n");
Iterator itMRequest = mRequest.keySet().iterator();
while (itMRequest.hasNext()) {
String tempKey = (String) itMRequest.next();
Object tempValue = mRequest.get(tempKey);
if (tempKey.startsWith("VENUS") || tempKey.startsWith("RANMIN")) {
continue;
}
if (RmStringHelper.ArrayContainString(ignoreName, tempKey)) {
continue;
}
String tempValueNew = "";
if (tempValue instanceof String) { //如果是单值,直接注入
tempValueNew = RmStringHelper.replaceStringToscript((String)tempValue); //从数据库中取出来以后需要转换1次
rtValue.append(" indexArray[indexArray.length] = "" + tempKey + "";n");
rtValue.append(" mForm["" + tempKey + ""] = "" + tempValueNew + "";n");
} else if (tempValue instanceof String[]) { //如果是多值,放入数组
rtValue.append(" indexArray[indexArray.length] = "" + tempKey + "";n");
String[] myArray = (String[]) tempValue;
if ( tempKey.equals("cmd") ){
tempValueNew = RmStringHelper.replaceStringToscript(myArray[0]);
rtValue.append(" mForm["" + tempKey + ""] = "" + tempValueNew + "";n");
} else {
rtValue.append(" mForm["" + tempKey + ""] = [");
for (int i = 0; i < myArray.length; i++) {
if (i > 0)
rtValue.append(",");
tempValueNew = RmStringHelper.replaceStringToscript(myArray[i]);
rtValue.append(""" + tempValueNew + """);
}
rtValue.append("];n");
}
} else if (tempValue instanceof Timestamp) { //如果是时间戳,直接注入
if(tempValue == null) {
continue;
}
tempValueNew = RmStringHelper.replaceStringToscript(tempValue.toString().substring(0,19));
rtValue.append(" indexArray[indexArray.length] = "" + tempKey + "";n");
rtValue.append(" mForm["" + tempKey + ""] = "" + tempValueNew + "";n");
} else if (tempValue instanceof BigDecimal){
tempValueNew = RmStringHelper.replaceStringToscript(tempValue.toString());
rtValue.append(" indexArray[indexArray.length] = ""
+ tempKey + "";n");
rtValue.append(" mForm["" + tempKey + ""] = ""
+ tempValueNew + "";n");
} else {
if(tempValue != null) {
RmStringHelper.log("在回写页面时,遇到了未知java类型:" + tempValue);
}
continue;
}
}
rtValue.append(" for(var i=0; i
以上就是本文的全部内容,希望对大家的学习有所帮助。



