smartgwt client pro version 4.1
Firefox 26.0
Java 1.7 for building
I have file open and file save as menu items. For the file open item, I want to prompt the user with a file open dialog from the users machine. Once, the user selects, the file, I will parse the file on the server side and send a Java bean to the client.
For the file save item, I want to send a Java object from the client to the server. Prompt the user for a file name and save the object on the client's machine.
The fileupload canvas item is not exactly what I am looking for. I am able to use the RemoteServiceServlet for the file save as operation and send the object to be saved from the client to the server. However, the saving operation does not display a File save as dialog.
@Override
public Boolean saveModel(Model model) throws IllegalArgumentException {
String xmlStr = writeModel(model).toString();
if (null == xmlStr) {
return false;
}
try {
HttpServletResponse response = getThreadLocalResponse();
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment;filename=\"model.xml\"");
InputStream is = new ByteArrayInputStream(xmlStr.getBytes("UTF-8"));
ServletOutputStream os = response.getOutputStream();
byte[] bufferData = new byte[1024];
int read = 0;
while ((read = is.read(bufferData)) != -1) {
os.write(bufferData, 0, read);
}
os.flush();
os.close();
is.close();
}
catch (IOException e) {
return false;
}
return true;
}
Firefox 26.0
Java 1.7 for building
I have file open and file save as menu items. For the file open item, I want to prompt the user with a file open dialog from the users machine. Once, the user selects, the file, I will parse the file on the server side and send a Java bean to the client.
For the file save item, I want to send a Java object from the client to the server. Prompt the user for a file name and save the object on the client's machine.
The fileupload canvas item is not exactly what I am looking for. I am able to use the RemoteServiceServlet for the file save as operation and send the object to be saved from the client to the server. However, the saving operation does not display a File save as dialog.
@Override
public Boolean saveModel(Model model) throws IllegalArgumentException {
String xmlStr = writeModel(model).toString();
if (null == xmlStr) {
return false;
}
try {
HttpServletResponse response = getThreadLocalResponse();
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment;filename=\"model.xml\"");
InputStream is = new ByteArrayInputStream(xmlStr.getBytes("UTF-8"));
ServletOutputStream os = response.getOutputStream();
byte[] bufferData = new byte[1024];
int read = 0;
while ((read = is.read(bufferData)) != -1) {
os.write(bufferData, 0, read);
}
os.flush();
os.close();
is.close();
}
catch (IOException e) {
return false;
}
return true;
}
Comment