Announcement

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

    fileitem upload download question

    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;
    }

    #2
    Take a look at the Upload & Download samples in the Showcase.

    It looks like your code is most similar to the "Custom Download" sample. If so, you are missing the call to rpc.doCustomResponse() shown in the sample.

    Comment


      #3
      What modifications are required to web.xml, etc?

      Hi,

      I modified the onClick method to 'send', object myModel (which is serializable) to the server.


      public void onClick(com.smartgwt.client.widgets.menu.events.MenuItemClickEvent p1) {
      Model myModel = manager.getCurModel();

      Criteria criteria = new Criteria();
      criteria.addCriteria("model", myModel);
      DSRequest dsRequest = new DSRequest();
      dsRequest.setOperationId("save model");
      dsRequest.setDownloadResult(true);
      DataSource ds = new DataSource();
      ds.fetchData(criteria, null, dsRequest);
      }

      From the showcase sample, I cannot determine the updates to web.xml so that the applicable servlet is invoked.

      From the code section in showcase, the following servlet is called:

      public class CustomDownload {

      public void downloadData(DSRequest dsRequest, RPCManager rpc)
      {
      DSResponse dsResponse = new DSResponse(); ...

      Where is the mapping? Also, are there special jar files I have to include?


      Thanks

      Comment


        #4
        There are no modifications to web.xml required. This request, like all other requests where no special dataURL is specified, goes to IDACall. See the Installation Instructions (SGWTEESetup), each servlet is explained. But again nothing but default settings is required here.

        Note that your object model may be serializable in the Java sense but GWT is not true Java. The docs for rpcRequest.data explain what objects may be included in a Record and what to expect on the server side.

        Comment


          #5
          Absolute mimimum to pass objects between client server with file dialog

          When I tried the sample project, I was getting errors.
          http://forums.smartclient.com/showthread.php?t=28788

          I updated my current project as given in http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/docs/SgwtEESetup.html

          Now, the simple project no longer works. I am getting the following when attempting to open the browser.

          HTTP ERROR: 503

          SERVICE_UNAVAILABLE

          RequestURI=/MyPage.html


          Is everything described for SgwteeSetup required to pass serializable objects between server and client and open up file dialog to read /write information to users computer?

          Thanks

          Comment


            #6
            Yes, the installation instructions are complete and known to work.

            See previous response about the specific behaviors regarding serializable objects.

            Unfortunately there's not much we can do with a claim that the installation instructions end in a 503 error. That sounds like whatever application server you're working with has become fundamentally wedged in some way such that it's not even loading the start page (which is *before* SmartGWT is even involved).

            Comment


              #7
              running ant hosted

              Hi,

              I am running ant hosted (Jetty). I am not using Tomcat.

              Standard gwt allows passing serialized java objects (i.e. gwt java classes) between client and server. I am only attempting to pass this type of object.

              Comment


                #8
                Once again, if you are getting a 503 error just loading the bootstrap file, SmartGWT is not yet involved. You haven't made it possible to help you on this at all yet (no error message, no server logs, nothing), but it's also not a SmartGWT problem at all. You'll need to get your Eclipse/Jetty setup back to a normal state, then we can potentially help with SmartGWT issues.

                As far as the serialization (which appears totally unrelated to your issues above, by the way), GWT-RPC offers some limited ability to serialize certain Java objects, but comes with severe drawbacks which you can read about in the FAQ. We strongly recommend against GWT-RPC in general for those reasons, even more so for this case.

                And once again, the actual behavior of SmartGWT's serialization is covered in the docs, under rpcRequest.data.

                Comment

                Working...
                X