5 Replies Latest reply on Sep 10, 2007 10:07 PM by yevster

    HTTPService sending parameters

      I am looking for a way to send in a list of parameters to my JSP. I already know how to use <mx:Request> tag, but it only allows for a predefined number of parameters (at design time). What i want to do is to send in an x number of parameters in, basically, send in an XMLList contents as parameter list.

      The documentation on HTTPService has a method xmlEncode() and xmlDecode(). I could not get it to work and there aren't any working examples out there. I guess i could serialize an XMLList into a xml string myself and send it as one parameter field and then parse it in jsp... or use JSON.

      Is there a workable design pattern for sending complex objects in?

      If i was to use HTTPService in ActionScript, theoretically i could dynamically add parameters to the Request object. I just don't know how to create and use HTTPService fom AS... can someone show me? is it hs:HTTPService = new HTTPService(); hs.request.add("key", "value"); ??

      Thanks for any help.
        • 1. Re: HTTPService sending parameters
          yevster Level 1
          I think I found the asnwer: http://www.adobe.com/devnet/flex/articles/complex_data_02.html

          The example snippet from that site:
          form1.send({xml: XMLUtil.as2xml(employee, "employee")});

          They serialize an object employee and set it as a value to key 'xml'. In the jsp you would access it by request.getProperty("xml"); and then you would have to parse the xml.

          Any comments from the group?
          • 2. Re: HTTPService sending parameters
            JKohn99 Level 1
            Sending xml is one way. You can also just dynamically add paramaters to
            a request object.

            rq:Object = new Object();
            rq.parm1 = "p1;
            rq.parm2 = "p2";
            rq.parm3 = "p3";


            I've only done this in a servlet.
            In your servlet (I assume a jsp would be similar)
            you can:

            request.getParameter("parm1"); etc.

            • 3. HTTPService sending parameters
              levancho Level 3
              there is a little more JSONized ( *Arguably* convenient) way :

              var myobj:Object = {

              or inlining it :


              of course you can build this object within loop just as easily:

              // inside forLoop for example :

              myOObj["somenewparamName"] = someObject; etc ...

              • 4. HTTPService sending parameters
                levancho Level 3
                I personaly don't agree what they do in that example you showed ( http://www.adobe.com/devnet/flex/articles/complex_data_02.html), that is way too much extra unnecessary fanciness that adds additional layer of logic on both sides, flex and jsp,which does not really give any justifiable FLEXIbility to developer
                why would you want to generate xml then on server side parse xml when you can just as easily build request parametes on flex side iteratively and same thing on jsp (with existing servler/jsp API ) Exaple : iterate through all or partial request parameters with code something like this :

                for (java.util.Enumeration e = request.getParameterNames(); e.hasMoreElements() ;) {
                String name = (String) e.nextElement();
                String value = request.getParameter(name);

                • 5. Re: HTTPService sending parameters
                  yevster Level 1
                  Great responses. I will have to try JKohn99 and levancho's examples. They are much simpler then XML.
                  The reason I considered an XML was to be able to send a complex data structure back to my back end. But I herd that you can do nested objects in JSON: {attr1:value, attr2:{attr2a:value2}}. So it might be an avenue.

                  For a lazy programmer like myself, is there a serializer/deserializer that converts an object graph into json In actionscript.? Similar to what Axis2 does in java world (converts java objects to SOAP XML and back again)