问题描述
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";}