PDA

View Full Version : Column config



raivis
11 Jan 2012, 11:41 PM
Hello, all!

I was wondering if there is a better way of data binding for grids in GXT v3.0? Like it is for fields:

textfield.setName("fieldName");
This way it is possible to generate input form. For grid one have to write lots of boilerplate code like this:

ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Company");
ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

Is there a way one could generate it automatically?

raivis
17 Jan 2012, 1:48 AM
Anyone?

Colin Alworth
22 Jan 2012, 2:15 PM
In both 2.x and 3, defining an editor field is always easier than a grid: in 2.x, textfield.setName("myFieldName") allows you to use it with FormBinding, whereas in 3, the GWT Editor Framework[1] is used, where you simply create a package-protected field in your Editor instance, `TextField myFieldName;`.

Grids in 2 require declaring the header text, the property to act on, and the width of the column. GXT 3 requires the same basic details, though in both versions, it is often useful to provide additional details (how to render the cell, what editor to use). The constructor has changed somewhat, to accept a ValueProvider instead of a String (for better type safety, and compatibility with any POJO instead of just ModelData), but otherwise it hasn't changed.

If you are looking to find a way to generate ColumnConfig instances automatically, remember how many settings often need to be configured. If you just need a way to simply display data, then just setting the ValueProvider instance should be enough, but to customize the header, width, editor, etc will require more changes. This is possible to implement, though not simple - look into implementing Generators to provide this, much like how PropertyAccess instances provide ValueProviders. This isn't a simple topic that can be easily addressed in a forum post, instead start with some research into existing Generators in both GWT and Ext GWT.

[1] http://code.google.com/webtoolkit/doc/latest/DevGuideUiEditors.html

raivis
22 Jan 2012, 10:38 PM
Thanks for the answer. I am more concerned of writing hundreds (if not thousands) of boilerplate editor views with edit fields and grids than writing common generator. But I guess it is not possible since GWT Editor framework requires code to be written before compiling it.
I think I'll just make a code generator that will make my editors and grid creation code from bean models before compiling final application.