Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Custom Export Format

    I would like to know if its possible to have data exported to a custom format, meaning non of the ones in the ExportFormat enum?

    I am using SmartGWT 2.5 Power Edition.

    I have searched a bit and can't find another post with this question.
    Thank you in advance.

    As an example. I would like to export a simple "text" file, .txt , formated with each field having a varying set of spaces.
    Say I have data that has the following fields: FirstName, LastName, Date of Birth.
    And I want the output to look something like......

    LastName _________________ FirstName________DOB

    The "_" signifies a space.
    Last edited by ajmarrer; 29 Nov 2011, 10:33.

    #2
    Yes. Add a DMI to a "fetch" operationType and call RPCManager.doCustomResponse(). At that point you have a DSResponse which can provide the fetched data as a List or Maps, and you can write whatever you want to the servlet outputStream.

    Comment


      #3
      I created my DMI class and created the method where I would like to format my response.

      However, I am not clear on how I can format the response and send it back to the user for downloading.

      Would a short sample code of formatted text file be available to see?

      Say output the following to a file called sample.txt:

      Line 1: Hello
      Line 2: Out There!

      Comment


        #4
        Write the data you want to send to the client to the servletResponse outputStream. At this point it's just standard Java servlets stuff.

        Comment


          #5
          I think I just realized the first place I might be going wrong....

          It was suggested that I "Add a DMI to a "fetch" operationType and call RPCManager.doCustomResponse()"....

          So therefore I went ahead and did the following in my datasource xml file:

          Code:
          <operationBinding operationType="fetch" operationId="customExport">
              <serverObject classname="com.export.MyCustomExportDMI" lookupStyle="new" />
              <serverMethod>customExportMethod</serverMethod>
              <exportAs>txt</exportAs>
              <exportFilename>sample.txt</exportFilename>
              <lineBreakStyle>dos</lineBreakStyle>
          </operationBinding>
          Which I believe is referred to as DataSource DMI?

          However having read over your suggestion again, I believe the suggestion points to me using what is referred to as RPC DMI...is this correct?

          If so, how do I use RPC DMI, is it through the operationBinding like I have it now? or through some other mechanism?

          Comment


            #6
            You want to use DataSource DMI. Now, in your MyCustomDataSourceDMI method, call doCustomResponse, and write to the servletResponse outputStream.

            Comment


              #7
              I decided recently to give this topic a whirl again and it finally dawned on me what your suggestions meant. Now I am able to output the data in the format I have provided. However I am also having an additional problem.

              I am not able to get the file to be exported as a ".txt" I continue to get the file exported as a ".csv". How can I change the extension of the file to be what I need i to be?

              Additionally, as a bonus, would it be possible to export 2 different files through one export command? Or would there be a way to provide a ".zip" file export with the files that I need. The theory here is that I need to provide 2 separate formatted files that take the same exact inputs and ideally would like them to be done simultaneously.
              Last edited by ajmarrer; 28 Feb 2012, 07:24.

              Comment


                #8
                To add some extra detail... I've attempted to get the filename that I would like by doing each of the following...

                1) Setting it in my ds.xml file within my operationBinding
                2) Setting it client side using DSRequest.setExportAs() and DSRequest.setExportFileName()
                3) Setting it server side, in the DSRequest using DSRequest.setExportAs() and DSRequest.setExportFileName() before calling dsRequest.execute().

                Neither one of these gives me the desired result...any hints are welcomed and thanks in advance for the help!

                Comment


                  #9
                  Ok I have even further detail as to what is going on and hopefully a solution can be suggested.

                  I went ahead and on the Client-Side used

                  Code:
                  DSRequest propertiies = new DSRequest();
                  properties.setOperationId("customTEXT");
                  properties.setExportToFileSystem(true);
                  properties.setExportFileName("hello.txt");
                  
                  listGrid.exportData(properties);
                  In server side i FIRST tried the following...
                  Code:
                  public DSResponse customTEXT(DSRequest dsRequest, RPCManager manager, HttpServletRequest request, HttpServletResponse response)
                  {
                  return dsRequest.execute();
                  }
                  The result that I obtained was that I was able to get the filename and extension that I desired to be downloaded, albeit, no custom formatting.
                  Additionally, it was saved to the export.location path designated in my server.properties file, also with the correct name and extension.

                  Then I tried the following server side...
                  Code:
                  public DSResponse customTEXT(DSRequest request, RPCManager manager, HttpServletRequest request, HttpServletResponse response)
                  {
                  manager.doCustomResponse();
                  return dsRequest.execute();
                  }
                  When I select export, a blank page is displayed with no information and I can see that my browser URL has changed from "localhost:8080/war" (running from Tomcat) to "localhost:8080/war/project/sc/IDACall/hello.txt?isc_rpc=1&isc_v=SC_SNAPSHOT-2012-01-30_v8.2p&isc_tnum=10"

                  I then changed the Client-Side code as follows, only removing the call to setExportFileName()....
                  Code:
                  DSRequest propertiies = new DSRequest();
                  properties.setOperationId("customTEXT");
                  properties.setExportToFileSystem(true);
                  
                  listGrid.exportData(properties);
                  I received my exportWindow with the filename "Results.csv" which was expected.
                  However, I went to my export.location and no file was exported to the FileSystem.

                  Lastly, I made the following server side change....
                  Code:
                  public DSResponse customTEXT(DSRequest dsRequest, RPCManager manager, HttpServletRequest request, HttpServletResponse response)
                  {
                  manager.doCustomResponse();
                  dsRequest.setExportFileName("hello.txt");
                  return dsRequest.execute();
                  }
                  The result of this test was that a download window with a filename of "Results.csv" was displayed AND once again there was no file exported to the FileSystem at the designated location of export.location.


                  Any insight as to why these things are occurring?
                  Last edited by ajmarrer; 29 Feb 2012, 11:30.

                  Comment


                    #10
                    You are doing a custom export, so do not use the client-side exportData() API, which is for built-in exports. Just initiate the export with DataSource.fetchData(), and make sure you set downloadResult.

                    Comment


                      #11
                      I got it working by setting the following.

                      Code:
                      servletResponse.setContentType("text/plain")
                      servletResponse.setHeader("Content-Disposition", "attachment; filename=hello.txt");
                      Is this correct/safe?


                      Additionally, Instead of having the response create a Save/As dialog for the user client-side. Is there a way that I use this same DMI operation to simply create a file on the FileSystem at a designated location in webRoot?

                      And then later use a button to pull the file from the FileSystem and create the Save/As dialog for the user to download?

                      Comment

                      Working...
                      X