动态表单中的值转换问题(Map)

问题描述

publicStringadd()throwsException{Documentdocument=newDocument();document.setTitle(docInfo.getTitle());document.setDescription(docInfo.getDescription());//处理Map数据//将ActionForm中的Map数据,按照表单定义对应的类型进行转换,并设置到document对象即可if(docInfo.getProperties().isEmpty()){document.setProperties(null);}else{intworkflowId=docInfo.getWorkflowId();//流程对应的表单定义FlowFormflowForm=this.flowFormManager.findFlowForm(workflowId);if(flowForm==null){document.setProperties(null);}else{MapdocumentProperties=newHashMap();//拿到表单定义对应的所有的域定义Setfields=flowForm.getFields();for(Iteratoriter=fields.iterator();iter.hasNext();){FormFieldfield=(FormField)iter.next();StringpropertyName=field.getFieldName();FieldTypepropertyType=field.getFieldType();//根据表单属性名称,从Map中将页面上传过来的原始值拿出来Objectsource=docInfo.getProperties().get(propertyName);Objecttarget=null;if(source!=null){//对于输入的字符串//if(sourceinstanceofString&&!propertyType.getType().equals("java.io.File")){if(sourceinstanceofString[]&&!propertyType.getType().equals("java.io.File")){ClasstargetClass=Class.forName(propertyType.getType());//利用convertUtils工具,将从页面上传过来的字符串//转换为FormField对应的FieldType所指定类型的对象(把字符串转换成目标类型)////////////////////////////////问题产生:当我在想得到target的具体值时,得到的是克西马;target=ConvertUtils.convert(source.toString(),targetClass);}//如果表单域是上传文件if(propertyType.getType().equals("java.io.File")){//注意:如果界面上传的是文件,struts2自动转换为File类型Filefile=(File)source;//target=file.get}//现在需要将target的值赋予document对象if(target==null){thrownewSystemException("无法处理输入的值");}DocumentPropertydocumentProperty=newDocumentProperty();Stringtype=propertyType.getType();if(type.equals("java.io.File")){documentProperty.setJava_io_File((byte[])target);}if(type.equals("java.lang.Integer")){documentProperty.setJava_lang_Integer(Integer.parseInt((target.toString())));}if(type.equals("java.lang.String")){documentProperty.setJava_lang_String(target.toString());}System.out.println(target.toString()+"99999999");documentProperties.put(propertyName,documentProperty);}}document.setProperties(documentProperties);}}this.documentManager.addDocument(document,docInfo.getWorkflowId(),getCurrentUse().getId));return"addSuccess";}

时间: 2024-08-02 07:17:40

动态表单中的值转换问题(Map)的相关文章

jQuery中设置form表单中action值的实现方法_jquery

html代码: <form id="myFormId" name="myForm" action="" method="post"> <input type="hidden" id="inParam" name="inParam" /> <input type="hidden" id="tstype"

jsp 网站开发-在 jsp中为什么用request.getParameter()的方法获取不到表单中的值?

问题描述 在 jsp中为什么用request.getParameter()的方法获取不到表单中的值? //新闻编号 int nid=Integer.parseInt(request.getParameter("nid")); //新闻主题编号 int ntid=1; String ntitle=request.getParameter("title"); String nauthor=request.getParameter("atuthor")

js简单获取表单中单选按钮值的方法_javascript技巧

本文实例讲述了js简单获取表单中单选按钮值的方法.分享给大家供大家参考,具体如下: HTML部分如下: <form> <tr bgcolor="#FFFFFF"> <td width="84" height="23" rowspan="3" align="center" valign="middle" bordercolor="#999999&qu

$_POST 变量用于收集来自 method=&quot;post&quot; 的表单中的值

$_POST 变量 $_POST 变量是一个数组,内容是由 HTTP POST 方法发送的变量名称和值. $_POST 变量用于收集来自 method="post" 的表单中的值.从带有 POST 方法的表单发送的信息,对任何人都是不可见的(不会显示在浏览器的地址栏),并且对发送信息的量也没有限制. 例子 <form action="welcome.php" method="post"> Enter your name: <in

$_GET 变量用于收集来自 method=&quot;get&quot; 的表单中的值

$_GET 变量 $_GET 变量是一个数组,内容是由 HTTP GET 方法发送的变量名称和值. $_GET 变量用于收集来自 method="get" 的表单中的值.从带有 GET 方法的表单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏),并且对发送的信息量也有限制(最多 100 个字符). 例子 <form action="welcome.php" method="get"> Name: <input type=

asp取动态表单中数据并写入xml文件,用xsl显示

xml|动态|数据|显示|xml   1.动态表单的界面,从csdn论坛上参考 <html><head><title>无标题文档</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><script language="javascript">var curRow=null;var

asp取动态表单中数据并写入xml文件,用xsl显示_应用技巧

<html> <head> <title>无标题文档</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <script language="javascript"> var curRow=null; var y=1; function selectRow(){ var e=

struts2中Action怎样获取动态表单中的多行数据

问题描述 一: struts-config.xml 配置<struts-config> <form-beans> <form-bean name="trafficForm" type="com.ccit.safetm.controller.traffic.TrafficForm"></form-bean> </form-beans> <action-mappings> <action pa

将form表单中的元素转换成对象的方法适用表单提交_javascript技巧

复制代码 代码如下: function serializeObject(form){ var o ={}; $.each(form.serializeArray(),function(index){ if(o[this['name']]){ o[this['name']] = o[this['name']] +","+this['value']; }else{ o[this['name']] = this['value']; } }); return o; }