简体   繁体   中英

How do I keep my collection in sorted order when sent as ArrayCollection and received as java.util.Set on the server?

I've developed a web application using Flex 4.5, Java, BlazeDS and Spring.

I just discovered that when I fetch a collection (java.util.Set) from the server as an ArrayCollection, sort the ArrayCollection in the Flex web application and send it back to the server, this collection is received by the server as unsorted java.util.Set.

Any suggestion on how I can keep the collection sorted when sent to the server?

You'll need to use an object on the AS side and a Map on the Java side. In AS, put all the elements from your arraycollection in one object like this

            var list:ArrayCollection = new ArrayCollection();
            var obj:Object = new Object();
            list.addItem("test");
            list.addItem("test2");
            for(var i=0;i<list.length;i++){
                obj[i] = list.getItemAt(i);
            }

After that , send the obj to the Java side - an AS object will be serialized to a Java Map. On the server side you will have the positions as the keys from your map, so you will be able to rebuild the order (the Java code is trivial, so I'm not going to write it down here).

Why does it need to be sorted in-transit? I would just sort it when the server receives it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM