Good afternoon, dear SmartGWT developers!
I have a fundamental(for me and my project) question. It's like "Am I behaving right or wrong?"
Every time when I look in SmartGWT showcase examples concerning grids, I see this:
I know that almost everywhere in your examples you use XMLs as the datasources. And I understand how do you do it.
In my project I make calls to the server-side using RemoteServiceServlet class and AsyncCallback. And therefore in method onSuccess of AsyncCallback I use recieved result object to change my front-end correspondingly.
For example, I want to get list of objects using a stored procedure and update my ListGrid. Here is the code for it:
For sure you can imagine that my MyObjectRecord class is something like this:
I feel that something I do here I do wrong, although it all works. I mean the architecture thing. I assume that SmartGWT offers much more efficient way to do it.
I read the SmartGWT_Quick_Start_Guide.pdf and found lot of information about data binding and data sources there, BUT there are different approaches and there is said that I need SmartGWT server for some of them(can't recognize for which exactly).
Therefore considering that I'm using free SmartGWT version, can I use different approach in my task here? Can I use data sources here? How can I use it?
For sure I can make a static xml file on the server and read it from client using setDataSource, but I need to dynamically fill the grid, i.e. after server returns a resultset. Or do I need every time create this xml file from a RemoteServiceServlet and parse it from client somehow? Which approach can I use using free version of SmartGWT?
Thank you very much in advance! Your help in this question would be highly appreciated.
I have a fundamental(for me and my project) question. It's like "Am I behaving right or wrong?"
Every time when I look in SmartGWT showcase examples concerning grids, I see this:
Code:
DataSource dataSource = someDS.getInstance(); listGrid.setDataSource(dataSource);
In my project I make calls to the server-side using RemoteServiceServlet class and AsyncCallback. And therefore in method onSuccess of AsyncCallback I use recieved result object to change my front-end correspondingly.
For example, I want to get list of objects using a stored procedure and update my ListGrid. Here is the code for it:
Code:
ObjectsGetterServiceAsync objectsGetterService = GWT.create(ObjectsGetterService.class);
final ListGrid listGrid = new ListGrid();
listGrid.setShowAllRecords(true);
listGrid.setAlternateRecordStyles(true);
ListGridField objectNameField = new ListGridField("name", "Name", 200);
ListGridField objectTypeField = new ListGridField("type", "Type", 200);
ListGridField objectValueField = new ListGridField("value", "Value", 150);
ListGridField objectdescriptionField = new ListGridField("desrc", "Description", 500);
listGrid.setFields(new ListGridField[] {objectNameField, objectTypeField, objectValueField, objectdescriptionField});
listGrid.setCanResizeFields(true);
AsyncCallback<List<MyObject>> callback = new AsyncCallback<List<MyObject>>()
{
@Override
public void onSuccess(List<MyObject> result)
{
if((result != null) && (result.size() > 0))
{
MyObjectRecord [] records = new MyObjectRecord[result.size()];
int i = 0;
for(MyObject obj: result)
{
MyObjectRecord r = new MyObjectRecord();
r.setName(obj.getName());
r.setType(obj.getType());
r.setValue(obj.getValue());
r.setDescription(obj.getDescription());
records[i] = r;
i++;
}
listGrid.setData(records);
}
else
SC.say("There is no objects!");
}
@Override
public void onFailure(Throwable caught)
{
SC.warn("Getting objects failed!");
}
};
objectsGetterService.getObjects(callback);
Code:
public class MyObjectRecord extends ListGridRecord
{
public Integer getName()
{
return getAttribute("name");
}
public void setName(String name)
{
setAttribute("name", name);
}
// etc...
}
I read the SmartGWT_Quick_Start_Guide.pdf and found lot of information about data binding and data sources there, BUT there are different approaches and there is said that I need SmartGWT server for some of them(can't recognize for which exactly).
Therefore considering that I'm using free SmartGWT version, can I use different approach in my task here? Can I use data sources here? How can I use it?
For sure I can make a static xml file on the server and read it from client using setDataSource, but I need to dynamically fill the grid, i.e. after server returns a resultset. Or do I need every time create this xml file from a RemoteServiceServlet and parse it from client somehow? Which approach can I use using free version of SmartGWT?
Thank you very much in advance! Your help in this question would be highly appreciated.
Comment