Expand my Community achievements bar.

IViewCursor sort with managed data issue?

Avatar

Level 2

Hi All

I have a question about using IViewCursor on a managed collection with my AIR 1.5.x application.

By no means a expert using dataservices, but up until now, I have not had many majors issues (mostly) have not being able to work out.

...but first to prove my approach is ok, I have created some dummy data which appears to work fine.

When I run the cursor over the test data I correctly get only 7 items found and added.

The test data sort routines have been commented out. (using arrayCollection)

My Question is, why will this not work on my managed data collection held in the model.stockModel.source ?

The cursor returns the entire collection. Surely it is something simple I have missed:)

below is the basic cursor sort routines and the have added (just in case I am doing something fundamentally wrong) the actionscript class files and the java dto s'.....but the are really straight forward.

code snippit:

//unmanaged test data to search

                   var arrayCollection:ArrayCollection    =    new ArrayCollection();
                  
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"_Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
;//wont be found
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"_Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
;//wont be found
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});
                   arrayCollection.addItem({ web_Category_Level_1:"_Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"});//wont be found
                  

//model.stockModel.source is the managed data from my dataservice.fill()



                    var length:int        =    model.stockModel.source.length;//managed data
                    //
var length:int        =   arrayCollection.length;


                    var cursor:IViewCursor;
                    var foundList:ArrayCollection=new ArrayCollection();
                   

               //cursor.findFirst(values) - match all 3 fields
                    var values={ web_Category_Level_1:"Aboriginal", web_Category_Level_2:"Boomerangs",web_Category_Level_3:"Bunabiri Brigalow"}


                    if(length>0)
                    {

                       // var sortField:SortField = new SortField(null, true);
                        var sort:Sort = new Sort();
                        var sortArray:Array    =    new Array();
                        var found:Boolean=false;
               

                    //build query array with object for sort.fields
                            sortArray.push( new SortField("web_Category_Level_1", true) );

                            sortArray.push( new SortField( "web_Category_Level_2", true ) );

                            sortArray.push( new SortField( "web_Category_Level_3", true ) );

                      
                        //sort.fields = [sortField];
                       
                        if(sortArray.length)
                        {
                            cursor    =    model.stockModel.source.createCursor();
                            //cursor    =    arrayCollection.createCursor();
                           
                            sort.fields    =    sortArray;
                       
                            model.stockModel.source.sort = sort;
                            //arrayCollection.sort = sort;


                            model.stockModel.source.refresh();

                            //arrayCollection.refresh();


                            found    =    cursor.findFirst( values )

                            if(found){
                                while(!cursor.afterLast)
                                {
                                    var foundItem    =    cursor.current;
                                    foundList.addItem( foundItem );
                                    cursor.moveNext();
                                }
                            }
                           
                        }   



this is a actionscript class of my managed dto.



package dto.Category
{
    import dto.Stock.StockDTO;
   

   
    [Managed]
    [RemoteClass(alias="dto.Category.CategoryItemDTO")]
    public class CategoryItemDTO extends StockDTO
    {
        /**
         * We extend Stock so we get web_category_level_x properties
         *
         *
         */
         
        public function CategoryItemDTO()
        {
            super();
        }
        public var title:String="undefined"
    }
}




.....and the matching java dto:



package dto.Category;

import java.util.Date;
import java.util.HashMap;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

import dto.Stock.StockDTO;

/**
* Simple value Object for CategoryTable
*
*/

public class CategoryItemDTO extends StockDTO{
   
    static final long serialVersionUID = 103844514947365244L;//needed???
   
    /**
     * id
     * LEVEL
     *
     * extend stock to get web_Category_Level_x fields
     *
     */

    public CategoryItemDTO()
    {
        super();
    }


}


Any help much appreciated

Jasen

0 Replies