Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Get Values of DataSource directly?

    Hi,
    this is probably a very easy question... :)
    I have the following DataSource which displays values correctly when attached to a ListGrid:
    Code:
    public class SearchDataSource extends XJSONDataSource {
    	public static final int NAME_FIELD_LEN = 256;
    	
    	private static int searchID = 0;
    	
    	
    	public SearchDataSource(SearchRequest request) {
    		setID(getNextSearchID());
    		
    		setDataURL("http://...".concat(URL.encode(request.keyword)));
    		setRecordXPath("/");
    		
    		DataSourceIntegerField pkField = new DataSourceIntegerField("ID");
    		pkField.setHidden(true);
    		pkField.setPrimaryKey(true);
    		
    		DataSourceTextField name = new DataSourceTextField("name", MainLayout.constants.name(), NAME_FIELD_LEN, true);
    		// more data DataSourceTextField initializations ....
    		
    		setFields(pkField, name);
    	}
    }
    Now I want to get a List/Array of all the items in DataSourceTextField name (without using a list grid or anything). How can I do this? Thanks
    Last edited by Zordon; 6 Jun 2011, 12:36.

    #2
    fetchData() with a callback handler.

    Comment


      #3
      thanks
      for fetchData() I need a Criteria as parameter. What is the value for that criteria since I want to retreive and not set a value??
      Is there a fetchData() example somwhere? Since I'm not sure I understand the Criteria and DSCallback correctly...

      Comment


        #4
        Criteria lets you limit the results assuming the server is capable of using the values. You can pass an empty criteria to get everything. The callback handler is called with the data upon receiving a response. You can then do what you want with it.

        Comment


          #5
          Thanks.
          DSCallback is an interface, so how do I use it?
          Code:
          DSCallback callback;
          this.fetchData(new Criteria(), callback);
          Do I have to implement the callback myself?

          edit. the data is already requested in my case via JSON, so doing another callback operation seems to be a lot of work? Can't I just access it somehow? Does ListGrid access the data via callback, too?
          Last edited by Zordon; 6 Jun 2011, 13:16.

          Comment


            #6
            Here is a trivial example which may assist. You may replace the null criteria with some criteria if you need filtering.

            Code:
                        	DSCallback dsCallback = new DSCallback() {
                        		@Override
                    	    	public void execute(DSResponse response, Object rawData, DSRequest request) {
                        			Record[] records = response.getData();
            
                        			for (Record record : records) {
            				//Do something useful with the result set
                        			}
            
                    	    	}
                        	};
                        	ds.fetchData(null, dsCallback);

            Comment


              #7
              Thanks.
              The foreach loop is exactly what I was planning to to:)

              For others who might need this thread. You can't pass null here or you get an exception, so I passed an empty Criteria:
              ds.fetchData(new Criteria(), dsCallback);

              Comment

              Working...
              X