ravi.m183
31 Jan 2010, 9:59 PM
Hi,
I am using Gxt2.1 for my application development. In one of my modules, I need to read an excel file (using upload facility) and send the contents of the same to a Grid. To upload and read the excel file I am using FileUploadField of Gxt. The FileUploadField is added to a FormPanel which is submitted to a servlet. My client side code is as follows:
FormPanel formPanel = new FormPanel();
formPanel.setFrame(false);
formPanel.setBorders(false);
formPanel.setHeaderVisible(false);
formPanel.setAction(GWT.getModuleBaseURL() + "excel-upload-service");
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formPanel.setWidth(350);
FileUploadField uploadField = new FileUploadField();
uploadField.setWidth(200);
uploadField.setFieldLabel("File");
Button uploadButton = new Button("Upload", null);
uploadButton.addListener(Events.Select,new Listener<ButtonEvent>(){
public void handleEvent(ButtonEvent be) {
formPanel.submit();
}
});
formPanel.add(uploadField);
formPanel.add(uploadButton);
My servlet doPost() method which reads the excel file content is as follows:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(req);
/* This method reads the excel contents and stores it in a customised object */
readExcelFile(items);
/* I want to send this object back to client side so that it can be used in a Grid */
}
catch (FileUploadException e) {
e.printStackTrace();
}
}
The problemt I am facing is that, I am storing the contents of the excel file in a serialized object which I want to send back to client side so that it can be used to display the contents in a Grid. But i dont know how to go about doing this.
Any help would be appreciated.
Thanks
Ravi
I am using Gxt2.1 for my application development. In one of my modules, I need to read an excel file (using upload facility) and send the contents of the same to a Grid. To upload and read the excel file I am using FileUploadField of Gxt. The FileUploadField is added to a FormPanel which is submitted to a servlet. My client side code is as follows:
FormPanel formPanel = new FormPanel();
formPanel.setFrame(false);
formPanel.setBorders(false);
formPanel.setHeaderVisible(false);
formPanel.setAction(GWT.getModuleBaseURL() + "excel-upload-service");
formPanel.setEncoding(Encoding.MULTIPART);
formPanel.setMethod(Method.POST);
formPanel.setButtonAlign(HorizontalAlignment.CENTER);
formPanel.setWidth(350);
FileUploadField uploadField = new FileUploadField();
uploadField.setWidth(200);
uploadField.setFieldLabel("File");
Button uploadButton = new Button("Upload", null);
uploadButton.addListener(Events.Select,new Listener<ButtonEvent>(){
public void handleEvent(ButtonEvent be) {
formPanel.submit();
}
});
formPanel.add(uploadField);
formPanel.add(uploadButton);
My servlet doPost() method which reads the excel file content is as follows:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try
{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(req);
/* This method reads the excel contents and stores it in a customised object */
readExcelFile(items);
/* I want to send this object back to client side so that it can be used in a Grid */
}
catch (FileUploadException e) {
e.printStackTrace();
}
}
The problemt I am facing is that, I am storing the contents of the excel file in a serialized object which I want to send back to client side so that it can be used to display the contents in a Grid. But i dont know how to go about doing this.
Any help would be appreciated.
Thanks
Ravi