public DataSourceTextField DataSourceDateFieldUploadingPic(String timeId,String timeName){ //SC.showConsole(); //"file" new DataSourceValidateFile(); textuploadFile=new DataSourceTextField(timeId,"<nobr>"+timeName+"</nobr>"); formItem=new CanvasItem(timeId,"<nobr>"+timeName+"</nobr>"); formItem.setWidth("200"); final DynamicForm picForm=new DynamicForm(); picForm.setEncoding(Encoding.MULTIPART); CanvasItem pictureShowItem=new CanvasItem("pictureShowItem","照片"); pictureShowItem.setRowSpan(3); final Image image=new Image(); image.setUrl(GWT.getHostPageBaseURL()+"icons/fwsp.png"); Canvas c=new Canvas(); c.addChild((image)); pictureShowItem.setCanvas(c); UploadItem pictureItem =new UploadItem("file","<nobr>"+timeName+"</nobr>"); SubmitItem submitPic=new SubmitItem("submitPic","上传照片"); picForm.setItems(pictureShowItem,pictureItem,submitPic); picForm.setAction(GWT.getHostPageBaseURL()+"personalInfo/upload"); final Window tipwin=new Window(); tipwin.setTitle("上传提示窗口"); HTMLPane htmlPane=new HTMLPane(); htmlPane.setContents("<IFRAME name=\"uploadFrame2018\" class=gwt-Frame style=\"WIDTH:100%; HEIGHT:100%\" src=\""+GWT.getHostPageBaseURL()+"uploading.gsp\"></IFRAME>"); htmlPane.setSize("100%","100%"); htmlPane.moveto(0,20); tipwin.addChild(htmlPane); tipwin.addCloseClickHandler(new CloseClickHandler() { public void onCloseClick(CloseClientEvent event) { mainService.getPicName(new AsyncCallback() { public void onFailure(Throwable caught) { } @Override public void onSuccess(Object result) { strValue=result.toString(); image.setUrl(GWT.getHostPageBaseURL()+"picture/"+result.toString()+"?"+Random.nextDouble()); tipwin.clear(); } }); } }); picForm.setTarget("uploadFrame2018"); submitPic.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { tipwin.setSize("300","300"); tipwin.setAutoCenter(true); tipwin.show(); tipwin.bringToFront(); picForm.submitForm(); } }) ; picForm.setIsGroup(true); picForm.setGroupTitle("上传照片"); formItem.setCanvas(picForm); return textuploadFile; }
public DynamicForm createForm(){ DataSource dataSource=new DataSource(); dataSource.setClientOnly(true); DataSourceValidateFile file=new DataSourceValidateFile(); dataSource.setFields(file.DataSourceDateFieldUploadingPic("attachment1","上传访谈文件")); final DynamicForm form=new DynamicForm(); form.setUseAllDataSourceFields(true); form.setDataSource(dataSource); form.setFields(file.formItem); return form; }
VisitRecordDTO visit=new VisitRecordDTO(); visit.setAttachment1(form.getValueAsstring("attachment1"));
public String getPicName(){
return session["stupic"]; }
def upload={ params.each{ println it } Commonsmultipartfile uploadFile=params.file if(!uploadFile.isEmpty()){ String oFileName=uploadFile.getoriginalFilename() Date fname=new Date() Long fff=fname.getTime() def fileSaveName=fff+oFileName.substring(oFileName.lastIndexOf(".")) def fileSavePath=request.getRealPath("/")+"uploads\\"+ fileSaveName println fileSavePath uploadFile.transferTo(new File(fileSavePath) ) session.setAttribute("stupic",fileSaveName) render "上传成功,请关闭提示窗口!" }else{ } }
如果有不会写的 请给本人留言 谢谢