zorba-the-geek / smartgwt

Automatically exported from code.google.com/p/smartgwt
0 stars 0 forks source link

Add methods to access Record objects from a datasource #103

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. /
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

nighty build (jan 29th)

Please provide any additional information below.

ListGrid provide a method getRecord to retreive a record. It could be
usefull to have the same kind of method in DataSource class. Currently, we
can add, remove, update but not just get a record.

Original issue reported on code.google.com by ricard.i...@gmail.com on 2 Feb 2009 at 10:33

GoogleCodeExporter commented 9 years ago
Use fetchData(Criteria, DSCallback) passing the criteria of records to be 
fetched or null if not filtering is required. 
Register a DSCallback and call DSResponse.getData() to get an array of Records.

Original comment by sanjiv.j...@gmail.com on 9 May 2009 at 12:45

GoogleCodeExporter commented 9 years ago
what about more specific problems?
we have two data sources (nr 1): the first has groups with an id and a name. the
second (nr 2) holds data with a reference (id) to the groups. we try to display 
the
data in a list grid and group the data by the group id and display the 
groupname as
group title.

we set the datasource (nr 2) as datasource for the list grid and grouped it. 
then we
set a groupValueFunction for the getting the name of the groups from the first 
data
source (nr 1). we fetched it, passing the groupid as a criteria and got the 
requested
data in a callback function, we triggered.
now we have to wait for the callback function to return the requested value. 
But in
the meantime returned an empty value.

example:

       ListGridField group = new ListGridField("groupid", "group", 250);
       userAgentGroup.setGroupValueFunction(new GroupValueFunction () {

            String name = null;

            @Override
            public Object getGroupValue(Object value, ListGridRecord record,
                    ListGridField field, String fieldName, ListGrid grid) {

                final int groupID = (Integer) value;

                Criteria cr = new Criteria();
                cr.addCriteria("id", groupID);

                userAgentGroups.fetchData(cr, new DSCallback() {

                    @Override
                    public void execute(DSResponse response, Object rawData,
                            DSRequest request) {

                        Record[] test = response.getData();
                        for ( int i= 0; i < test.length; i++) {
                            name = test[i].getAttributeAsString("name");
                        }
                    }

                });

                return name; // name is empty, at this time !
            }

        });

Is there an other solution or wouldn´t it be easier to acces the record sets 
by a
function the data source provides?

Original comment by m.mil...@newelements.de on 11 Aug 2009 at 5:21

GoogleCodeExporter commented 9 years ago
This is a situation that you need to come up with a solution for based on your
application requirements since RPC calls are asynchronous. If the number of 
groups
are limited, you can try preloading them and keeping a Map of the groupID --> 
name
around.

Original comment by sanjiv.j...@gmail.com on 11 Aug 2009 at 5:27