This worked for me. Thanks. On Mon, May 10, 2010 at 9:48 AM, Ajay Chitre <chitre.a...@gmail.com> wrote:
> Albert, > > Not sure if you are still stuck on this.. but if you make the following 2 > changes this should work for you... > > 1) Change 'onInitialize' method to return 'form'. (It is returning > 'vPanel' in your code.) > 2) Add following line: > > fileUpload.setName("myFile"); > > This should work. > > > > On Thu, May 6, 2010 at 11:15 AM, Ajay Chitre <chitre.a...@gmail.com>wrote: > >> Adding some more info... >> >> >> >> In the debugger when I set a breakpoint in 'onInitialize' at this line:* >> >> RootPanel.get().add(form); * >> >> the form seems to be built properly as follows: >> >> >> <form method="post" enctype="multipart/form-data" action=" >> http://127.0.0.1:8888/showcase/myFormHandler" target="FormPanel_1"><table >> cellpadding="0" cellspacing="0"><tbody><tr><td style="vertical-align: top;" >> align="left"><div class="gwt-HTML"><b>Select a >> file:</b></div></td></tr><tr><td style="vertical-align: top;" >> align="left"><input id="gwt-debug-cwFileUpload" class="gwt-FileUpload" >> type="file"></td></tr><tr><td style="vertical-align: top;" align="left"><div >> class="gwt-HTML"><br></div></td></tr><tr><td style="vertical-align: top;" >> align="left"><button class="gwt-Button" tabindex="0" type="button">Upload >> File</button></td></tr></tbody></table></form> >> >> >> But under firebug, the form shows up as this... >> >> <form target="FormPanel_1" action=" >> http://127.0.0.1:8888/showcase/myFormHandler" >> enctype="multipart/form-data" method="post"></form> >> >> So seems like there's something in the Showcase application framework >> that's causing this. Any ideas? >> >> >> >> >> On Wed, May 5, 2010 at 8:01 AM, Something Something < >> mailinglist...@gmail.com> wrote: >> >>> Hello, >>> >>> I am writing a GWT application based on the 'Showcase' sample ( >>> http://gwt.google.com/samples/Showcase/Showcase.html). I am trying to >>> get the 'File Upload' feature to work. I have changed the 'CwFileUpload' >>> class as follows: >>> >>> public Widget onInitialize() { >>> // Create a FormPanel and point it at a service. >>> * final FormPanel form = new FormPanel();* >>> form.setAction(GWT.getModuleBaseURL() + "*myFormHandler*"); >>> >>> // Because we're going to add a FileUpload widget, we'll need to set >>> the >>> // form to use the POST method, and multipart MIME encoding. >>> form.setEncoding(FormPanel.ENCODING_MULTIPART); >>> form.setMethod(FormPanel.METHOD_POST); >>> >>> // Create a vertical panel to align the content >>> VerticalPanel vPanel = new VerticalPanel(); >>> form.setWidget(vPanel); >>> // Add a label >>> vPanel.add(new HTML(constants.cwFileUploadSelectFile())); >>> >>> // Add a file upload widget >>> final FileUpload fileUpload = new FileUpload(); >>> fileUpload.ensureDebugId("cwFileUpload"); >>> vPanel.add(fileUpload); >>> >>> // Add a button to upload the file >>> Button uploadButton = new Button(constants.cwFileUploadButton()); >>> uploadButton.addClickHandler(new ClickHandler() { >>> public void onClick(ClickEvent event) { >>> String filename = fileUpload.getFilename(); >>> if (filename.length() == 0) { >>> Window.alert(constants.cwFileUploadNoFileError()); >>> } else { >>> // Window.alert(constants.cwFileUploadSuccessful()); >>> form.submit(); >>> } >>> } >>> }); >>> vPanel.add(new HTML("<br>")); >>> vPanel.add(uploadButton); >>> >>> // Add an event handler to the form. >>> form.addSubmitHandler(new SubmitHandler() { >>> @Override >>> public void onSubmit(SubmitEvent event) { >>> if (fileUpload.getFilename().length() == 0) { >>> Window.alert("Must select a valid file"); >>> event.cancel(); >>> } >>> } >>> }); >>> >>> form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { >>> public void onSubmitComplete(SubmitCompleteEvent event) { >>> // When the form submission is successfully completed, this >>> // event is fired. Assuming the service returned a response of >>> type >>> // text/html, we can get the result text here (see the FormPanel >>> // documentation for further explanation). >>> Window.alert(event.getResults()); >>> } >>> }); >>> * RootPanel.get().add(form);* >>> >>> // Return the layout panel >>> return vPanel; >>> } >>> >>> >>> The code in *MyFormHandler *is given below (Note: This was directly >>> copied from the Google Appengine FAQ page): >>> >>> public void *doPost*(HttpServletRequest req, HttpServletResponse res) >>> throws ServletException, IOException { >>> try { >>> ServletFileUpload upload = new ServletFileUpload(); >>> res.setContentType("text/plain"); >>> >>> FileItemIterator iterator = upload.getItemIterator(req); >>> while (iterator.hasNext()) { >>> // IT NEVER GETS IN THIS LOOP >>> FileItemStream item = iterator.next(); >>> InputStream stream = item.openStream(); >>> >>> if (item.isFormField()) { >>> LOG.warning("Got a form field: " + item.getFieldName()); >>> } else { >>> LOG.warning("Got an uploaded file: " + item.getFieldName() + >>> ", name = " + item.getName()); >>> >>> // You now have the filename (item.getName() and the >>> // contents (which you can read from stream). Here we just >>> // print them back out to the servlet output stream, but you >>> // will probably want to do something more interesting (for >>> // example, wrap them in a Blob and commit them to the >>> // datastore). >>> int len; >>> byte[] buffer = new byte[8192]; >>> while ((len = stream.read(buffer, 0, buffer.length)) != -1) { >>> res.getOutputStream().write(buffer, 0, len); >>> } >>> } >>> } >>> } catch (Exception ex) { >>> throw new ServletException(ex); >>> } >>> } >>> >>> When form is submitted, no "FileItems" (meaning form fields) are returned >>> in the Request object. I have tried moving the FormPanel to Showcase.java >>> and tried several combinations, but nothing is working :( Any ideas on >>> debugging this further will be greatly appreciated. Please help. >>> >>> Thank you. >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Google Web Toolkit" group. >>> To post to this group, send email to google-web-toolkit@googlegroups.com >>> . >>> To unsubscribe from this group, send email to >>> google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/google-web-toolkit?hl=en. >>> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to google-web-tool...@googlegroups.com. > To unsubscribe from this group, send email to > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.