3 Replies Latest reply on Dec 23, 2008 10:15 PM by Naseem_Khan

    Flex + Sending ArrayCollection to Server + Request Scope

    Naseem_Khan
      Hi All,

      I have a requirement where I have to send an ArrayCollection instance containing actionscript instances to server side. Server side component is java servlet.

      Could anyone please tell me how this can be done.

      I hav explored flex APIs where I get reference to sending as key/value. Here this is not feasible as I have a collection of .as instances and each .as instance is composed of 20 string objects.

      I have one idea I can get the whole ArrayCollection on the server side by request scope, if I can bind the same ArrayCollection in request scope with some key in mxml page. Can it be done.

      If I am in one jsp page from where I am forwarding to another jsp, then what I will do is in first jsp, I will write:
      request.setAtribute("SomeKey", instance);

      In second jsp, I will write
      List list = (List)request.getAttribute("SomeKey");

      I have no idea of how request.setAttribute is done in mxml page. Can it be done. Can anyone help me here. If this is not possible, is there any other way of doing this.

      Many Thanks,

      Best Regards,
      Nazz
        • 1. Re: Flex + Sending ArrayCollection to Server + Request Scope
          atta707 Level 2
          request.setAttribute() is NOT available from withing Flex. It's a server side only construct for servlets/jsps/struts tag lib etc.

          from flex you'll need to send this data as key/value pairs thru HTTPService (assuming that's what you're using).

          Now you don't have to convert all the elements into a separate key/value pairs. You can convert each object in the array collection into XML or JSON and set that value to a unique key. Alternatively you can convert the whole array collection into XML or JSON format and send it as string to server where your built-in XML parser and/or third party JSON library to reconstruct request parameter(s) to object in java.

          Hope this helps.

          ATTA
          • 2. Flex + Sending ArrayCollection to Server + Request Scope
            Naseem_Khan Level 1
            Hi,

            Thanks for the reply. Apologies for updating you late on this.

            I have downloaded JSON api from here: JSON API

            I have placed the as3corelib.swc file in my WEB-INF/flex/lib folder, I have imported the JSON class in mxml page using import com.adobe.serialization.json.JSON;

            when I hit the browser, it gives me following error on the browser:

            quote:


            1 Error, 1 Exception found.

            Error /nazz/SampleJSON.mxml
            unable to load SWC as3corelib.swc



            Exception flex2.compiler.swc.SwcException$SwcNotLoaded


            Here is the stacktrace from the server log:

            quote:


            12/21 20:07:55 ERROR
            unable to load SWC as3corelib.swc

            12/21 20:07:55 ERROR flex2.compiler.swc.SwcException$SwcNotLoaded
            at flex2.compiler.swc.SwcCache.getSwc(SwcCache.java:230)
            at flex2.compiler.swc.SwcCache.getSwcs(SwcCache.java:174)
            at flex2.compiler.swc.SwcCache.getSwcGroup(SwcCache.java:78)
            at flex2.compiler.swc.SwcCache.getSwcGroup(SwcCache.java:67)
            at flex2.compiler.CompilerSwcContext.load(CompilerSwcContext.java:52)
            at flex2.server.j2ee.IncrementalCompileFilter.fullCompile(IncrementalCompileFilter.java:186)
            at flex2.server.j2ee.IncrementalCompileFilter.compileMxml(IncrementalCompileFilter.java:113)
            at flex2.server.j2ee.BaseCompileFilter.mxmlToSwf(BaseCompileFilter.java:286)
            at flex2.server.j2ee.BaseCompileFilter.invoke(BaseCompileFilter.java:72)
            at flex2.server.j2ee.RecompileFilter.invoke(RecompileFilter.java:38)
            at flex2.server.j2ee.AboutFilter.invoke(AboutFilter.java:48)
            at flex2.server.j2ee.MxmlServlet.doGet(MxmlServlet.java:159)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
            at flex.bootstrap.BootstrapServlet.service(BootstrapServlet.java:85)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:252)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11P rotocol.java:743)
            at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
            at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.ja va:80)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
            at java.lang.Thread.run(Unknown Source)


            Please help.

            I'm using flex 2.

            Many Thanks,

            Best Rgds,
            NAZZ
            • 3. Re: Flex + Sending ArrayCollection to Server + Request Scope
              Naseem_Khan Level 1
              Hi,

              Just wanted to give you all an update. I tried xml approach and it worked. At server side, I have Apache Digester API to convert xml to java object.

              Right now I'm facing one issue. When no of record increases, then I'm not getting the string at server side. I have sent around 7,000 records to server as xml string. Each record(row) has further twenty columns. So, there are 7,000 such tags and within each tag, there are twenty property tags. I didn't get any string at server side.

              Is there any character limit constraint.

              Tx

              Rgds,
              Nazz