Stefan Mutschler Messages: 17 Registered: June 2012 Location: Baden-Baden, Germany
Junior Member
Can someone please give me a short sample how to download a server generated file in a client independant way? The scenario is to create a file (txt, pdf, whatever) on the server side and to save it to the server file system. Afterwards I would like to offer the user e.g. a button or linkbutton to request the generated file and save it to the local file system of the client machine.
I found the forum message on using the RemoteFileService which is working perfectly to read the content of the file and display it in the client window. But are there also methods that I can use to save the file on the client side independant from the client implementation I am working with?
There are two things to help:
1) The scout IFileChooser stores a file on the server side (in web ui) or on the local filesytem (rich client)
2) IDesktop.openBrowserWindow is used in web ui to publish a file to the user (download)
Typically both parts are used in an application:
Solution suggestion:
create an utility function in your project to download a (server) file on client side say DownloadUtility.java:
/**
* Used in web ui to force a file download for the user.
* <p>
* This is normally used on {@link IFileChooserField}s with {@link IFileChooserField#isTypeLoad()}=false.
* <p>
* In web ui the file chooser in save mode creates a temp file. The temp file is written by bsi crm logic and finally
* this utility method downloads the temp file to the end user.
*/
public static void downloadFile(File tempFile) {
if (!UserAgentUtility.isWebClient()) {
return;
}
IDesktop desktop = ClientJob.getCurrentSession().getDesktop();
if (!desktop.isGuiAvailable()) {
return;
}
desktop.openBrowserWindow(tempFile.getAbsolutePath());
}
In your form or menu or whatever create the file (on the server) and push it to the user
Stefan Mutschler Messages: 17 Registered: June 2012 Location: Baden-Baden, Germany
Junior Member
Yes, I know these posts, thanks. I think my question was a little bit confusing (and maybe rather content for another post?):
My question was targeting conventions. A scout project seems well structured to me and I just wanted to know if you have best practices / conventions where to store e.g. self written utility classes or other stuff not related directly to the standard scout project layout.
Maybe not really important, I'm just curious about your experiences...
Stephan Leicht Vogt Messages: 84 Registered: February 2010 Location: Baden Switzerland
Member
Hi Stefan
In our application we store utility classes in packages like these:
xx.yy.client.common e.g. ZzClientUtility for utility methods only used in the client.
xx.yy.shared.common e.g. ZzSharedUtility for utility methods used in the client and server.
xx.yy.server.common e.g. ZzServerUtility for utility methods only used in the server.
Stefan Mutschler Messages: 17 Registered: June 2012 Location: Baden-Baden, Germany
Junior Member
Yes, thank you. Now after you having replied I recognized that the SDK is also using 'common' as package naming e.g. 'xx.yy.server.services.common.sql'. I like naming conventions since they speed up development and help keeping the structure tidy.