How can we replace file upload dialog from GWT-EXT? What is the analogue
in SmartGWT?
Thanks,
--MG
in SmartGWT?
Thanks,
--MG
public void fileUpload(){ VLayout layout = new VLayout(); final DynamicForm uploadForm = new DynamicForm(); uploadForm.setEncoding(Encoding.MULTIPART); UploadItem fileItem = new UploadItem("image"); TextItem nameItem = new TextItem("imageName"); TextItem descriptionItem = new TextItem("description"); HiddenItem spaceImageIdItem = new HiddenItem("spaceImageId"); HiddenItem propertyIdItem = new HiddenItem("propertyId"); propertyIdItem.setValue(23); spaceImageIdItem.setValue(0); uploadForm.setTarget("hidden_frame"); uploadForm.setAction("/company/imageUploadRest.do"); IButton uploadButton = new IButton("Upload..."); uploadButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler(){ public void onClick(ClickEvent e){ uploadForm.submitForm(); } }); uploadForm.setItems(fileItem, nameItem, descriptionItem, spaceImageIdItem, propertyIdItem); layout.setMembers(uploadForm, uploadButton); RootPanel.get("tree1").add(layout); }
@RequestMapping("/imageUploadRest.do") @Transactional public void processImageUploadRest( @RequestParam("imageName") String imageName, @RequestParam("description") String description, @RequestParam("spaceImageId") String spaceImageId, @RequestParam("image") MultipartFile image, @RequestParam("propertyId") String propertyId, HttpServletResponse response) throws IOException, Exception { doImageSave(imageName, description, spaceImageId, image, propertyId); PrintWriter out = response.getWriter(); out.println("<response>"); out.println("<data>"); out.println("<status>0</status>"); out.println("</data> "); out.println("</response> "); } @Transactional public void doImageSave(String imageName, String description, String spaceImageId, MultipartFile image, String propertyId ) throws IOException, Exception { Long _spaceImageId = new Long(spaceImageId); ImageBlob imageBlob = new ImageBlob(image.getContentType(), image.getInputStream()); imageBlobDAO.create(imageBlob); }
<html> <head></head> <body bgcolor="#FFFFFF"> <iframe height="0" name="hidden_frame"> </iframe> ...
public class JavaScriptMethodHelper { private static int requestCounter = 0; public static String registerCallbackFunction(JavaScriptMethodCallback callback) { String callbackName = "callback" + (requestCounter++); createCallbackFunction(callback, callbackName); return callbackName; } private native static void createCallbackFunction( JavaScriptMethodCallback obj, String callbackName )/*-{ tmpcallback = function( j ){ obj.@example.JavaScriptMethodCallback::execute(Lcom/google/gwt/core/client/JavaScriptObject;)( j ); }; $wnd[callbackName]=tmpcallback; }-*/; }
package example; import com.google.gwt.core.client.JavaScriptObject; public interface JavaScriptMethodCallback { public void execute(JavaScriptObject obj); }
.... final HiddenItem callbackItem = new HiddenItem("callbackName"); uploadButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { String callbackName = JavaScriptMethodHelper.registerCallbackFunction(new JavaScriptMethodCallback() { public void execute(JavaScriptObject obj) { uploadFinished(obj); } }); callbackItem.setValue(callbackName); //set hidden item form.submitForm(); } });
<script type="text/javascript"> window.top.${callbackName}(...); </script>
public class JavaScriptMethodHelper { private static int requestCounter = 0; public static String registerCallbackFunction(JavaScriptMethodCallback callback) { String callbackName = "callback" + (requestCounter++); createCallbackFunction(callback, callbackName); return callbackName; } private native static void createCallbackFunction( JavaScriptMethodCallback obj, String callbackName )/*-{ tmpcallback = function( j ){ obj.@example.JavaScriptMethodCallback::execute(Lcom/google/gwt/core/client/JavaScriptObject;)( j ); }; $wnd[callbackName]=tmpcallback; }-*/; }
package example; import com.google.gwt.core.client.JavaScriptObject; public interface JavaScriptMethodCallback { public void execute(JavaScriptObject obj); }
.... final HiddenItem callbackItem = new HiddenItem("callbackName"); uploadButton.addClickHandler( new ClickHandler() { public void onClick(ClickEvent event) { String callbackName = JavaScriptMethodHelper.registerCallbackFunction(new JavaScriptMethodCallback() { public void execute(JavaScriptObject obj) { uploadFinished(obj); } }); callbackItem.setValue(callbackName); //set hidden item form.submitForm(); } });
<script type="text/javascript"> window.top.${callbackName}(...); </script>
<script type="text/javascript"> _methodName(...); </script>
<script type="text/javascript"> _alert('Hi'); </script>
<button onClick="javascript:_methodeName(...);">test</button>
Comment