Convert. Flex processes the types of containers returned by Java.

Source: Internet
Author: User
Tags set set

Of course, this topic is based on the use of blazeds to process remoteobject.

1. List and set

When Java returns list and set, flex can use arraycollection for processing.

 

Java code

  1. List list =
    New
    Arraylist ();
  2. List. Add (New
    Users (
    "ABC"
    ,
    "123"
    ));
  3. List. Add (New
    Users (
    "EFG"
    ,
    "123"
    ));
  4. List. Add (New
    Users (
    "Hij"
    ,
    "456"
    ));
  5. Return
    List;

Java code

  1. Set set =
    New
    Hashset ();
  2. Set. Add (New
    Users (
    "ABC"
    ,
    "123"
    ));
  3. Set. Add (New
    Users (
    "EFG"
    ,
    "123"
    ));
  4. Set. Add (New
    Users (
    "Hij"
    ,
    "456"
    ));
  5. Return
    Set;

Flex code

  1. Private function resulthandler (Event: resultevent): void {
  2. VaR array: arraycollection = event. Result As arraycollection;
  3. VaR STR: String = ""
    ;
  4. For (var I: Int = 0
    ; I <array. length; I ++ ){
  5. VaR anuser: Users = array. getitemat (I) as users;
  6. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  7. }
  8. Resultmessage. Text = STR;
  9. }

2. Map

MAP is regarded as an object in ActionScript. You only need to know the key of map, and you can use ". Key" to get the value of map.

 

Java code

 

  1. Map map =
    New
    Hashmap ();
  2. Map. Put ("one"
    , Anuser );
  3. Map. Put ("two"
    , Anuser );
  4. Map. Put ("three"
    ,
    New
    Users (
    "ABC"
    ,
    "123"
    ));
  5. Map. Put ("four"
    ,
    New
    Users (
    "EFG"
    ,
    "123"
    ));
  6. Map. Put ("five"
    ,
    New
    Users (
    "Hij"
    ,
    "456"
    ));
  7. Return
    Map;

Flex code

  1. Private function resulthandler (Event: resultevent): void {
  2. VaR STR: String = ""
    ;
  3. VaR anuser: Users = event. Result. One as users;
  4. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  5. Anuser = event. Result. Two as users;
  6. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  7. Anuser = event. Result. Three as users;
  8. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  9. Anuser = event. Result. Four as users;
  10. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  11. Anuser = event. Result. Five as users;
  12. STR + = anuser. username + ":"
    + Anuser. Password +
    "/N"
    ;
  13. Resultmessage. Text = STR;
  14. }

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.