I have to send file and their properties to GWT server.
For sending a file i used form panel.
public class BrowseFile extends DialogBox {
// more code
// ..
private FormPanel getFormPanel() {
if (formPanel == null) {
formPanel = new FormPanel();
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet");
formPanel.addSubmitHandler(new FormPanel.SubmitHandler(){
public void onSubmit(SubmitEvent event) {
// TODO Auto-generated method stub
setFilename(fileUpload.getFilename());
}
});
}
return formPanel;
}
}
all the properties of this file are in Hashmap
there are 2 dialog box Propertybox extends DialogBox
and
BrowseFile extends DialogBox
inside the constructor of PropertyBox there is BrowseFile
When PropertyBox constructor
setSize("600px", "670px");
setHTML("Add Document");
setWidget(getVerticalPanel());
browseFile = new BrowseFile();
The custom Property inside the PropertyBox depends on the class selected (Class is tree Widget)
On Server Side
public class FileUpload extends HttpServlet implements Servlet{
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(FileUpload.class
.getName());
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
byte[] buffer = new byte[115200];//
String fileName = null;
String mimetype = null;
String majorVersion = null;
InputStream stream = null;
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
stream = item.openStream();
if (item.isFormField()) {
//
} else {
fileName = item.getName();
mimetype = item.getContentType();
//
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
int len;
while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
output.write(buffer, 0, len);
}
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
Session session =RootFolder.getSession();
ContentStream contentStream = session.getObjectFactory()
.createContentStream(fileName, output.size(), mimetype, input);
}
For Creating a document in External repository i need Document Property in hasmap
folder.createDocument(Document Property,contentStream, VersioningState.MAJOR);
The Document property should be send to this class on onClick
event of Button ADD
of Document property Class
*****How to send this document property to server in class FileUpload *****