-
28 Feb 2012 5:32 AM #1
Data Binding
Data Binding
Hi!
I'm new to GWT / GXT.
How can I do generic data binding with a grid / tree / textfield, ...?
I've got a database with more than 500 tables and thousands of queries.
I can't create interafces and classes for every query!
The approach in the samples with classes an interafces for every object is ok for a small number of objects but not for a huge numer of objects.
So how can I handle this?
Thanks for your help!
-
25 May 2012 2:32 AM #2
Hi,
I have the same problem. We're creating a generic system for visualizing tables therefore we can't create a data model for each table.
With GXT 2.X you can use the ModelData interface to "create" those fields dynamically, but I can't find a solution for GXT 3.
Someone has already faced with this problem?
-
29 May 2012 9:26 AM #3
GXT 3 is if anything more flexible than 2.x - while it is encouraged to use bean-like objects, there is no reason you can't write a ModelData-like class with string-based properties.
Stores, DataLoaders, and DataProxys are all generic enough to handle any type at all, and the requirements of the data widgets are merely to implement a ValueProvider instance to read and write values as needed.
For a hypothetical example, you could pass Map<String, Double> as your data to and from the server. You'd then have a ListStore<Map<String, Double>>, and a Grid<Map<String, Double>>. Each column could have a hand made ValueProvider (this is just an interface, you can implement it however you'd like) that may look about like this:
You then could create ColumnConfig instances using these, something likeCode:public class MapValueProvider implements ValueProvider<Map<String, Double>, Double> { private final String property; public MapValueProvider(String property) { this.property = property; } public String getPath() { return property; } public Double getValue(Map<String, Double> object) { return object.get(property); } public void setValue(Map<String, Double> object, Double value) { object.put(property, value); } }
Several columns can be added with different properties they are reading from each row.Code:ColumnConfig<Map<String, Double>, Double> column = new ColumnConfig<Map<String, Double>, Double>(new MapValueProvider("prop");
Likely you'd be using your own Java class that exposes some kind of getter method to read from these dynamic properties, like ModelData did in 2.x.
-
13 Jun 2012 9:09 AM #4
Thank you for your reply.
Finally I've adopted a similar solution adding support for different types of data (String, Long, Boolean and so on) and creating a JSON data reader for runtime defined model data.
-
25 Jun 2012 5:00 AM #5
Hi,
I need a solution that combine defining specific data and a large data of any type String, date, float etc. (which can be created dynamically in my system with its type and value).
How can I create a grid that accepts different types of data: String, date, float and map<String, Object>?
Thanks for your help!
-
25 Jun 2012 7:31 AM #6
What have you tried? Even providing a simple example would go a long ways, as your question isn't quite clear.
If you want the Grid itself to contain any of these kinds of data, then you'll need to define a ListStore<Object> and a Grid<Object> with all of the issues that start from there - defining a ModelKeyProvider<Object> that works for String, Date, Float, Map<String, Object> for example.
The next step is to build a ColumnConfig and ValueProvider that can read from any of these types of data - though I'm not clear on how a grid row that is displaying a single String would make use of multiple columns.
If you want the Grid to contain some object defined in your code and have each _column_ display String, Date, Float, Map, then you'll define the ListStore and Grid to be generic on whatever it is you are holding the data in, and build a ValueProvider that can read from that object. Without seeing how you intend to store that data, I'd have to guess at what you might be thinking.
Define the data model first, some Java object that makes sense to contain all of these pieces of data, and it should become clear how to build a ValueProvider that can read that exact data type out, even if it involves an extra cast or two.


Reply With Quote