Edit: the newest version 1.1 support server-side paging and sorting, as explained later in this thread:
see http://forums.smartclient.com/showth...4370#post44370.
-----------------------
Hi everyone
I'm new to Smart GWT, and I thought I contribute a bit by creating a generic GwtRcpDataSource to minimize the pain of implementing a GWT RPC DataSource. This is based on the excellent work of Aleksandras and the smartgwt-extensions examples.
It's called GenericGwtRcpDataSource, and uses GenericGwtRpcDataSourceService and GenericGwtRpcDataSourceServiceAsync as counterparts.
To implement a GenericGwtRpcDataSource, you'll have to:
1. create a serializable data object (probably a POJO)
2. create a gwt rcp service, by extending GenericGwtRpcDataSourceService. Set its @RemoteServiceRelativePath annotation
3. create the asynchronous counterpart of the service by extending GenericGwtRpcDataSourceServiceAsync.
4. create your GwtRpcDataSource by extending GenericGwtRpcDataSource<D, T, SA>
5. Finally, code your Service implementation on the Server side, implementing your GenericGwtRpcService implementation:
Cheers!
marbot
see http://forums.smartclient.com/showth...4370#post44370.
-----------------------
Hi everyone
I'm new to Smart GWT, and I thought I contribute a bit by creating a generic GwtRcpDataSource to minimize the pain of implementing a GWT RPC DataSource. This is based on the excellent work of Aleksandras and the smartgwt-extensions examples.
It's called GenericGwtRcpDataSource, and uses GenericGwtRpcDataSourceService and GenericGwtRpcDataSourceServiceAsync as counterparts.
To implement a GenericGwtRpcDataSource, you'll have to:
1. create a serializable data object (probably a POJO)
Code:
import com.google.gwt.user.client.rpc.IsSerializable; public class YourDataObject implements IsSerializable { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Code:
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("yourservice") public interface YourService extends GenericGwtRpcDataSourceService<YourDataObject> { }
Code:
public interface YourServiceAsync extends GenericGwtRpcDataSourceServiceAsync<YourDataObject> { }
Code:
import java.util.ArrayList; import java.util.List; import com.google.gwt.core.client.GWT; import com.smartgwt.client.data.DataSourceField; import com.smartgwt.client.data.fields.DataSourceIntegerField; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.widgets.tile.TileRecord; public class YourGwtRcpDataSource extends GenericGwtRpcDataSource<YourDataObject, TileRecord, YourServiceAsync> { @Override public List<DataSourceField> getDataSourceFields() { List<DataSourceField> fields = new ArrayList<DataSourceField>(); DataSourceTextField itemNameField = new DataSourceTextField("itemName", "Product Name"); itemNameField.setRequired(true); fields.add(itemNameField); DataSourceIntegerField idField = new DataSourceIntegerField("itemId", "Product Id"); idField.setPrimaryKey(true); idField.setRequired(true); fields.add(idField); return (fields); } @Override public void copyValues(TileRecord from, YourDataObject to) { to.setName(from.getAttribute("itemName")); to.setId(from.getAttributeAsInt("itemId")); } @Override public void copyValues(YourDataObject from, TileRecord to) { to.setAttribute("itemName", from.getName()); to.setAttribute("itemId", from.getId()); } @Override public YourDataObject getNewDataObjectInstance() { return new YourDataObject(); } @Override public TileRecord getNewRecordInstance() { return new TileRecord(); } @Override public YourServiceAsync getServiceAsync() { return GWT.create(YourService.class); } }
Code:
public class YourServiceImpl extends RemoteServiceServlet implements YourService { @Override public YourDataObject add(YourDataObject data) { // your code here } @Override public List<YourDataObject> fetch() { // your code here } @Override public void remove(YourDataObject data) { // your code here } @Override public YourDataObject update(YourDataObject data) { // your code here } }
marbot
Comment