How can I get the fields list of a datasource? I could only find the functions to set them and I want to implement a general filter component similar with FilterBuilder that should get the fileds name from the datasource.
Announcement
Collapse
No announcement yet.
X
-
Emm ... do these methods work with the generated datasources from the smartGwt server ? I'm using the smartgwt 1.2 jar with your server (and not the 1.3 that comes with your ee distribution - which is older ? confused yet ? I was :-) ) and I have a simple datasource
Code:<?xml version="1.0" encoding="UTF-8"?> <DataSource ID="test1" serverType="sql" tableName="test1" > <fields> <field name="ID" title="Id" type="integer" primaryKey="true" required="true"/> <field name="NAME" title="Name" type="text" /> </fields> </DataSource>
Code:DataSource ds = DataSource.get(dsName); DataSourceField[] fields = ds.getFields();
If use
Code:DataSource ds = DataSource.get(dsName); String[] fieldNames = ds.getFieldNames();
Code:Uncaught JavaScript exception [com.google.gwt.core.client.JavaScriptException: (TypeError): 'data' is undefined number: -2146823279 description: 'data' is undefined at com.smartgwt.client.data.DataSource.getFieldNames(Native Method) at com.smartgwt.client.data.DataSource.getFieldNames(DataSource.java:2302) at com.smartgwt.sample.client.BuiltInDS.getDataSource(BuiltInDS.java:181) at com.smartgwt.sample.client.BuiltInDS.bindComponents(BuiltInDS.java:206) at com.smartgwt.sample.client.BuiltInDS.access$0(BuiltInDS.java:205) at com.smartgwt.sample.client.BuiltInDS$2.onRecordClick(BuiltInDS.java:73) at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:97) at com.smartgwt.client.widgets.grid.events.RecordClickEvent.dispatch(RecordClickEvent.java:1) at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:65) at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53) at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178) at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:66)] in http://localhost:8080/builtinds/hosted.html?builtinds, line 18
Comment
-
As an aside, and to speed things up since I'm in a different timezone I wonder if you could comment on my approach (and why I need the above method) as I maybe trying to reinvent something you have already (but I haven't been able to find it) .
I want to create a new form item for fields that have a foreign key but I want to do it with your dynamic/generated datasources.
I want to be able to display the foreign key in the form but allow the user to select a new value from a listgrid launched with the datasource of the other table. I see there are some datasource methods associated with SelectItem but to do what I want I think I'll need to at least subclass SelectItem or maybe even combine it with FormItemIcon. This involves taking the generated datasource, finding the field that is a foreign key and replacing the editor with one I have create ... Does this seem like the correct apporach ?
Comment
-
Originally posted by mhulsmanSounds like SelectItem will do exactly what you want. If you use the setPickListFields() method you can define the dropdown to have multiple columns. In fact once you set it to have multiple columns the dropdown looks exactly like a ListGrid and can even be sorted by any column.
Also I'm not sure if a drop down is the way I want to go as if the user is scrolling through a large list and clicks away for a second by mistake then they'll have to do it all again, a modal dialog with listgrid would be my preferred option. Thanks for the comments though ... all debate welcomed ...
Comment
-
Originally posted by IsomorphicIf you prefer not to use the dropdown approach, create a StaticTextItem with a FormItemIcon that launches a pop-up dialog to pick the record, and install that custom editor via DataSourceField.setEditorType()
So back to my original question is, is there a bug in getfields method (see earlier in the thread) or am I using it incorrectly ?
Comment
-
While you're working out wether the above is a bug or me doing something stupid maybe you can help me with browse button I'm trying to write.
I've followed your example but my FormItemIcon is only appearing when I double click on an entry in a Listgrid, for the Dynamic form it doesn't appear, I'm using you builtinds example as the basis for trying this out so the types are
Code:private ListGrid boundList; private DynamicForm boundForm; private DetailViewer boundViewer;
Heres where I modify the datasource ....
Code:DataSourceField field = ds.getField("test1_id"); if(field != null) { System.out.println("Found " + field.getTitle() ); String fk = field.getForeignKey(); if(fk != null) { System.out.println("Found " + fk); String[] split = fk.split("\\."); if((split != null) && (split.length > 0)) { System.out.println("Related " + split[0] ); BrowseItem browse = new BrowseItem(split[0],split[1]); field.setEditorType(browse); } else System.out.println("Split size "+split.length); } else System.out.println("No foreign key"); }
Code:public class BrowseItem extends TextItem { private Window listing; public BrowseItem(final String dataSource, final String attributeName) { FormItemIcon formItemIcon = new FormItemIcon(); setIcons(formItemIcon); addIconClickHandler(new IconClickHandler(){ @Override public void onIconClick(IconClickEvent event) { listing = new ListingWindowBrowse(dataSource, attributeName, BrowseItem.this); listing.setIsModal(true); listing.draw(); } }); System.out.println("Created browse"); } public void setSelected(String value) { setValue(value); if(listing != null) listing.markForDestroy(); redraw(); } }
Comment
-
I'm still trying to change the editor associated with a field in a dynamic form.
If I modify the datasource field using this
Code:DataSourceField field = datasource.getField("test1_id"); BrowseItem browse = new BrowseItem("test1","ID"); field.setEditorType(browse); DynamicForm boundForm.setDataSource(datasource);
If I modify the DynamicForm directly i.e. like this
Code:DynamicForm boundForm.setDataSource(datasource); BrowseItem browse = new BrowseItem("test1","ID"); browse.setTitle("Browse"); browse.setDisplayField("test1_id"); boundForm.setFields(browse);
Comment
-
Bump
Bump ! anyone on the isomorphic side ?
Originally posted by mike_macI'm still trying to change the editor associated with a field in a dynamic form.
If I modify the datasource field using this
Code:DataSourceField field = datasource.getField("test1_id"); BrowseItem browse = new BrowseItem("test1","ID"); field.setEditorType(browse); DynamicForm boundForm.setDataSource(datasource);
If I modify the DynamicForm directly i.e. like this
Code:DynamicForm boundForm.setDataSource(datasource); BrowseItem browse = new BrowseItem("test1","ID"); browse.setTitle("Browse"); browse.setDisplayField("test1_id"); boundForm.setFields(browse);
Comment
Comment