1. #1
    Ext User
    Join Date
    May 2008
    Location
    Phoenix, AZ
    Posts
    223
    Vote Rating
    0
    posta07 is on a distinguished road

      0  

    Default File Upload

    File Upload


    Does GXT provide file-uploading capabilities?
    If not, can someone help me understand how to implement it?
    Has anyone done this?

  2. #2
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    GWT 1.5 does, and I'm guessing a GXT version would be nice....

    http://google-web-toolkit-doc-1-5.go...1.5/index.html

  3. #3
    Ext User
    Join Date
    May 2008
    Location
    Phoenix, AZ
    Posts
    223
    Vote Rating
    0
    posta07 is on a distinguished road

      0  

    Default


    Darrell,

    are there plans for a GXT upload widget?

    The GWT one is very limited........

  4. #4

    Default


    I also think that it would be quite suitable to have a GXT upload widget.
    Ann,visit my site here

  5. #5
    Ext User Gianluigi's Avatar
    Join Date
    Aug 2008
    Location
    Florence Italy
    Posts
    7
    Vote Rating
    0
    Gianluigi is on a distinguished road

      0  

    Question


    I have the same problem. I have to use a FileUpload widget into a GXT formpanel...
    someone suggest to me to use GWT FileUpload into Gxt... i'm trying to do it but without success.

    FormPanel panel = new FormPanel();
    panel.setFrame(true);
    panel.setFieldWidth(210);
    panel.setLabelWidth(100);
    panel.setButtonAlign(HorizontalAlignment.CENTER);
    panel.setHeading("CVS Upload");
    panel.setIconStyle("icon-form");
    panel.setStyleAttribute("padding", "20");

    FileUpload fu = new FileUpload();
    fu.setName("file upload");
    fu.setTitle("File Upload:");
    fu.setVisible(true);
    fu.setPixelSize(300, 110);
    panel.add(fu);
    it doesn't works... any hints? Regards, Gianluigi

  6. #6
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    I've not tried this, so I can't say exactly what is wrong, but you will at least need to wrap non "form" widgets in an AdapterField -> anything that is not in com.extjs.gxt.ui.client.widget.form will need to be wrapped.

    see>> http://extjs.com/deploy/gxtdocs/com/...pterField.html

  7. #7
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    ...actually I don't think using the com.extjs.gxt.ui.client.widget.form.FormPanel is the right approach !!

    You really need to get a GWT FormPanel working, on its own without GXT widgets. When that is working, just drop it into a GXT ContentPanel.

    That should work.

  8. #8
    Ext User Gianluigi's Avatar
    Join Date
    Aug 2008
    Location
    Florence Italy
    Posts
    7
    Vote Rating
    0
    Gianluigi is on a distinguished road

      0  

    Default


    Yes the method that u suggested works, thanks

  9. #9
    Ext User
    Join Date
    May 2008
    Location
    Phoenix, AZ
    Posts
    223
    Vote Rating
    0
    posta07 is on a distinguished road

      0  

    Default


    it doesn't works... any hints?
    Here's how I did it, for those interested.
    Please drop me a comment if you know of a better way, or at least a way to improve what I've already done.

    On the client side, as gslender suggests, I had to get the FileUpload widget working outside of GXT first (to make sure everything was working). You must use the FormPanel (http://google-web-toolkit.googlecode...w-summary.html) widget with the FileUpload widget... since the FileUpload widget just wraps <input type="file"> it must be used within the <form></form> tags (which is what FormPanel wraps). Unfortunately, I found no way of doing file uploads with RPC :-(

    I used the following code

    Client:
    Code:
        public void onModuleLoad() {
            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);
            
            VerticalPanel panel = new VerticalPanel();
            form.setWidget(panel);
            
            // Create a FileUpload widget.
            FileUpload upload = new FileUpload();
            upload.setName("uploadFormElement");
            
            panel.add(upload);
            
            Button button2 = new Button("Submit", new ClickListener() {
                public void onClick(Widget sender) {
                    form.submit();
                }
            });
            
            // Add a 'submit' button.
            panel.add(button2);
            
            // Add an event handler to the form.
            form.addFormHandler(new FormHandler() {
    
                public void onSubmitComplete(FormSubmitCompleteEvent 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());
                }
    
                public void onSubmit(FormSubmitEvent event) {
                    // TODO Auto-generated method stub
    
                }
            });
            
            RootPanel.get().add(form);
    
        }
    <module>.gwt.xml
    add this line:
    Code:
    <servlet path="/myFormHandler" class="com.posta.samples.server.MyFormHandler"/>
    Server (using Commons-FileUpload and Commons-IO... with much guidance from this website: http://balusc.blogspot.com/2007/07/fileservlet.html):
    Code:
    public class MyFormHandler extends HttpServlet {
        
        
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            
            resp.setContentType("text/html");
            
            FileItem uploadItem = getFileItem(req);
            if(uploadItem == null) {
                resp.getWriter().write("NO-SCRIPT-DATA");
                return;
            }
            
            resp.getWriter().write(new String(uploadItem.get()));
            
            
        }
    
        private FileItem getFileItem(HttpServletRequest req) {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            
            try {
                List items = upload.parseRequest(req);
                Iterator it = items.iterator();
                
                while(it.hasNext()) {
                    FileItem item = (FileItem) it.next();
                    if(!item.isFormField() && "uploadFormElement".equals(item.getFieldName())) {
                        return item;
                    }
                }
            }
            catch(FileUploadException e){
                return null;
            }
            
            return null;
        }
    
    }
    I have also implemented file download and file delete. Let me know whether there is interest in that.

  10. #10
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    You should open a new thread in "Feature Requests" forum.