English English Spanish EspañolKorea한국어
Straker»Company»Blog»2008» Custom object queries in ZoomFlex

Custom object queries in ZoomFlex

This article looks at how you can use custom queries in ZoomFlex to return data from the server-side objects.

In the generated ZoomFlex code under the 'events' folder is a [classname]GetObjectsEvent.as file. This event has 3 properties which are columns,fieldName and fieldValue. This means when you dispatch the event you can pass in the columns you want to return from the database, the field name and field value which, in SQL terms would look something like

select columns from myclasstable where fieldname = fieldvalue

This is fine if you are only filtering on one field / value pair, but what happens if you want to filter on multiple name pair values?

The answer is pretty easy and is a quick 5 minute job. You simply need to add a new property to the event, add the relevant arguments to the command and delegate and do a quick change to the delegate getVOsByFilter function. 

Here are the steps

Open the generated  [classname]GetObjectsEvent.as file

Add an additional property called whereClause


        public var columns        : String = "";
        public var fieldName      : String = "";
        public var fieldValue     : String = "";
        public var whereClause     : String = "";

 Also update the other functions in the event 


        public function RssGetObjectsEvent(eventID:String, fieldName:String="", fieldValue:String="", whereClause:String="",columns:String="LABEL,OBJ_UUID,CREATED", handlers:Callbacks=null) {
            super(eventID, handlers, true, true);

            this.fieldName  = fieldName;
            this.fieldValue = fieldValue;
            this.columns    = columns;
            this.whereClause = whereClause;
        }

        override public function clone():Event {
            return new RssGetObjectsEvent(this.type).copyFrom(this);
        }

        override public function copyFrom(ev:Event):Event {
            // copy custom attributes
            if (ev is RssGetObjectsEvent){
                this.columns = (ev as RssGetObjectsEvent).columns;
                this.fieldName = (ev as RssGetObjectsEvent).fieldName;
                this.fieldValue = (ev as RssGetObjectsEvent).fieldValue;
                 this.whereClause = (ev as RssGetObjectsEvent).whereClause;
            }
            return super.copyFrom(this);
        }
   

 Now open the  command/[classname]Command.as

Find the getVO'sByFilter function and add the whereClause argument


        public function getVOsByFilter(event:RssGetObjectsEvent):void {

            var handlers : Callbacks         = new Callbacks(onResults_getVOsByFilter,this.onFault);
            var delegate : RssDelegate = new RssDelegate(handlers);

            delegate.getVOsByFilter(event.fieldValue,
                                        event.fieldName,
                                        event.columns,
                                        __model.blockSize,
                                        __model.maxRows,
                                        __model.startRow,
                                        event.whereClause);

        }  

Now open the delegates/[cassname]Delegate.as

Find the getVOsByFilter function and add the whereClause argument

   public function getVOsByFilter(    filterValue: String,
                                           filterName : String,
                                           columns    : String,
                                           blockSize  : int,
                                           maxRows    : int,
                                           startRow   : int ,
                                           whereClause:String):void {

 find where the whereClause is passed as an argument to the  server in the getVOsByFilter function and set it to the value of the passed in whereClause argument

    oArgs["whereClause"]                      = whereClause;

 

Now in your view you can add the code to dispatch the event

    dispatchEvent(new RssGetObjectsEvent(RssGetObjectsEvent.GETBYFILTER,"","","label='x' and created = 'test'","*",null));

As you can see I am filtering on label="x" and created="test" as well as returning all columns by using the "*" in my select clause. 

To test the event is dispatching correctly go to your application and run it so that the event dispatches (i'm presuming you are having the user interact with an input such as a button). Open the ZoomFlex debug screen and look for the event. If you click on the event you should see your whereClause being pased to the server. 

 

-------------Remote Object Arguments---------------------------
Value:
     whereClause : label='x' and created = 'test'
     blockSize : 200
     className : com.a3.model.vo::RssVO
     useBlockFactor : true
     selectFields : *
     startRow : 1
     filterValueText :
     filterValuefilterName : 

 

 

 

 

 

 


Comments

Add a comment



Add Comment