java中的接口是类吗
219
2023-07-18
form表单回写技术java实现
本文实例为大家分享了form表单回写技术,供大家参考,具体内容如下
回写支持的java拼js的方法:
/**
* 回写表单
*
* @param mRequest
* @return
*/
public static String writeBackMapToForm(Map mRequest) {
return writeBackMapToForm(mRequest, new String[]{}, "writeBackMapToForm");
}
/**
* 回写表单
*
* @param mRequest
* @param ignoreName 定义哪些key值的input不回写
* @return
*/
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) idnPOWkOiWttMRequest.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 rtValue.append(" writeBackValue(indexArray[i]);\n"); rtValue.append(" }\n"); rtValue.append(" }\n"); rtValue.append(jsFunctionName + "();\n"); return rtValue.toString(); } //通过此方法将request中的值放入mForm对象中 var mForm = new Object(); var indexArray = new Array(); function writeBackMapToForm() { indexArray[indexArray.length] = "att_id"; mForm["att_id"] = ""; indexArray[indexArray.length] = "businessTypeOID"; mForm["businessTypeOID"] = [""]; indexArray[indexArray.length] = "business_thttp://ype1"; mForm["business_type1"] = ""; indexArray[indexArray.length] = "business_type2"; mForm["business_type2"] = "1"; indexArray[indexArray.length] = "cmd"; mForm["cmd"] = "saveExamineRule"; indexArray[indexArray.length] = "document_content"; mForm["document_content"] = "s2"; indexArray[indexArray.length] = "file_path"; mForm["file_path"] = "http://"; indexArray[indexArray.length] = "file_template"; mForm["file_template"] = ""; indexArray[indexArray.length] = "gxl"; mForm["gxl"] = "null"; indexArray[indexArray.length] = "owner_id"; mForm["owner_id"] = "s1"; for(var i=0; i writeBackValue(indexArray[i]); } } writeBackMapToForm(); 关键语句jsp页面中加入后输出调用js方法: <% //表单回写 if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //如果request中取出的表单回写bean不为空 out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //输出表单回写方法的脚本 } Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES); System.out.print("infois:"+mapt.entrySet()); out.print("alert(1);"); %> //上面语句实际上注入的js格式内容如: var mForm = new Object(); var indexArray = new Array(); function writeBackMapToForm() { indexArray[indexArray.length] = "_function_id_"; mForm["_function_id_"] = "3670212500000000050"; indexArray[indexArray.length] = "cmd"; mForm["cmd"] = "listBusinessTypePage"; for(var i=0; i writeBackValue(indexArray[i]); } } writeBackMapToForm(); //注入后调用js回写表单方法 function writeBackValue(inputName) { if(form.elements[inputName] == undefined) { return false; } if(form.elements[inputName].value != undefined) { form.elements[inputName].value = mForm[inputName]; } if(form.elements[inputName].length != undefined ) { var thisValue = mForm[inputName]; if(mForm[inputName][0] == undefined) { thisValue = new Array(); thisValue[thisValue.length] = mForm[inputName]; } if(form.elements[inputName].length != null) { var tempLength = form.elements[inputName].length; for(var j=0; j var thisObj = form.elements[inputName][j]; for(var k=0; k if(thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } 以上就是本文的全部内容,希望对大家的学习有所帮助。
rtValue.append(" writeBackValue(indexArray[i]);\n");
rtValue.append(" }\n");
rtValue.append(" }\n");
rtValue.append(jsFunctionName + "();\n");
return rtValue.toString();
}
//通过此方法将request中的值放入mForm对象中
var mForm = new Object();
var indexArray = new Array();
function writeBackMapToForm() {
indexArray[indexArray.length] = "att_id";
mForm["att_id"] = "";
indexArray[indexArray.length] = "businessTypeOID";
mForm["businessTypeOID"] = [""];
indexArray[indexArray.length] = "business_thttp://ype1";
mForm["business_type1"] = "";
indexArray[indexArray.length] = "business_type2";
mForm["business_type2"] = "1";
indexArray[indexArray.length] = "cmd";
mForm["cmd"] = "saveExamineRule";
indexArray[indexArray.length] = "document_content";
mForm["document_content"] = "s2";
indexArray[indexArray.length] = "file_path";
mForm["file_path"] = "http://";
indexArray[indexArray.length] = "file_template";
mForm["file_template"] = "";
indexArray[indexArray.length] = "gxl";
mForm["gxl"] = "null";
indexArray[indexArray.length] = "owner_id";
mForm["owner_id"] = "s1";
for(var i=0; i writeBackValue(indexArray[i]); } } writeBackMapToForm(); 关键语句jsp页面中加入后输出调用js方法: <% //表单回写 if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //如果request中取出的表单回写bean不为空 out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //输出表单回写方法的脚本 } Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES); System.out.print("infois:"+mapt.entrySet()); out.print("alert(1);"); %> //上面语句实际上注入的js格式内容如: var mForm = new Object(); var indexArray = new Array(); function writeBackMapToForm() { indexArray[indexArray.length] = "_function_id_"; mForm["_function_id_"] = "3670212500000000050"; indexArray[indexArray.length] = "cmd"; mForm["cmd"] = "listBusinessTypePage"; for(var i=0; i writeBackValue(indexArray[i]); } } writeBackMapToForm(); //注入后调用js回写表单方法 function writeBackValue(inputName) { if(form.elements[inputName] == undefined) { return false; } if(form.elements[inputName].value != undefined) { form.elements[inputName].value = mForm[inputName]; } if(form.elements[inputName].length != undefined ) { var thisValue = mForm[inputName]; if(mForm[inputName][0] == undefined) { thisValue = new Array(); thisValue[thisValue.length] = mForm[inputName]; } if(form.elements[inputName].length != null) { var tempLength = form.elements[inputName].length; for(var j=0; j var thisObj = form.elements[inputName][j]; for(var k=0; k if(thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } 以上就是本文的全部内容,希望对大家的学习有所帮助。
writeBackValue(indexArray[i]);
}
}
writeBackMapToForm();
关键语句jsp页面中加入后输出调用js方法:
<% //表单回写
if(request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES) != null) { //如果request中取出的表单回写bean不为空
out.print(RmVoHelper.writeBackMapToForm((java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES))); //输出表单回写方法的脚本
}
Map mapt = (java.util.Map)request.getAttribute(RuleExamineConstants.REQUEST_WRITE_BACK_FORM_VALUES);
System.out.print("infois:"+mapt.entrySet());
out.print("alert(1);");
%>
//上面语句实际上注入的js格式内容如:
var mForm = new Object();
var indexArray = new Array();
function writeBackMapToForm() {
indexArray[indexArray.length] = "_function_id_";
mForm["_function_id_"] = "3670212500000000050";
indexArray[indexArray.length] = "cmd";
mForm["cmd"] = "listBusinessTypePage";
for(var i=0; i writeBackValue(indexArray[i]); } } writeBackMapToForm(); //注入后调用js回写表单方法 function writeBackValue(inputName) { if(form.elements[inputName] == undefined) { return false; } if(form.elements[inputName].value != undefined) { form.elements[inputName].value = mForm[inputName]; } if(form.elements[inputName].length != undefined ) { var thisValue = mForm[inputName]; if(mForm[inputName][0] == undefined) { thisValue = new Array(); thisValue[thisValue.length] = mForm[inputName]; } if(form.elements[inputName].length != null) { var tempLength = form.elements[inputName].length; for(var j=0; j var thisObj = form.elements[inputName][j]; for(var k=0; k if(thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } 以上就是本文的全部内容,希望对大家的学习有所帮助。
writeBackValue(indexArray[i]);
}
}
writeBackMapToForm();
//注入后调用js回写表单方法
function writeBackValue(inputName) {
if(form.elements[inputName] == undefined) {
return false;
}
if(form.elements[inputName].value != undefined) {
form.elements[inputName].value = mForm[inputName];
}
if(form.elements[inputName].length != undefined ) {
var thisValue = mForm[inputName];
if(mForm[inputName][0] == undefined) {
thisValue = new Array();
thisValue[thisValue.length] = mForm[inputName];
}
if(form.elements[inputName].length != null) {
var tempLength = form.elements[inputName].length;
for(var j=0; j var thisObj = form.elements[inputName][j]; for(var k=0; k if(thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } 以上就是本文的全部内容,希望对大家的学习有所帮助。
var thisObj = form.elements[inputName][j];
for(var k=0; k if(thisObj.value == thisValue[k]) { if( thisObj.checked != undefined) { thisObj.checked = true; break; } else if( thisObj.selected != undefined) { thisObj.selected = true; break; } } else { if( thisObj.checked != undefined) { thisObj.checked = false; } else if( thisObj.selected != undefined) { thisObj.selected = false; } } } } } } } 以上就是本文的全部内容,希望对大家的学习有所帮助。
if(thisObj.value == thisValue[k]) {
if( thisObj.checked != undefined) {
thisObj.checked = true;
break;
} else if( thisObj.selected != undefined) {
thisObj.selected = true;
break;
}
} else {
if( thisObj.checked != undefined) {
thisObj.checked = false;
} else if( thisObj.selected != undefined) {
thisObj.selected = false;
}
}
}
}
}
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~