Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT and DataSources

    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:
    Code:
    DataSource dataSource = someDS.getInstance();
    listGrid.setDataSource(dataSource);
    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:
    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);
    For sure you can imagine that my MyObjectRecord class is something like this:
    Code:
    public class MyObjectRecord extends ListGridRecord
    {
        public Integer getName()
        {
            return getAttribute("name");
        }
    
        public void setName(String name)
        {
            setAttribute("name", name);
        }
    
        // etc...
    }
    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.

    #2
    Please, help me with this issue, I really want my code to be more effective.

    Comment


      #3
      If you hadn't said you read the QuickStart Guide, we would tell you to read the QuickStart Guide.

      The most effective approach is to use Pro or above.

      If you aren't a professional developer (where it's a no-brainer to purchase at least Pro) the Data Integration chapter of the QuickStart Guide recommends several approaches for different scenarios. GWT-RPC (what you're using) is not one of them.

      Comment


        #4
        Thank you for your reply.

        So as I've understood you correctly, if I wish to continue using Free version, my two only ways are either to use GWT-RPC like I do now, or use hard-coded xmls as datasources, like you do in the showcase, am I right?

        The minimum level where I can use DataSources like it's described in the QuickStart guide is the Pro level, right?

        Comment


          #5
          Incorrect... and, sorry, but no idea how to help you except to recommend a careful re-read of the QuickStart Guide sections already mentioned. It lays all this out very clearly.

          Comment

          Working...
          X