Alius, thank you for your solution, it is working perfectly! Now i want to integrate this with filter and sorting support, i'll let you know.
I post here a working example of server-side paging support, since your example is client-side based and may be confusing for a newbye (like me :-)
I created a FetchResult class (generic) to carry all fetch result information from the server call.
At the moment this includes:
- the total row count
- the startrow returned from the server (which will be the same as that requested from the client)
- the endrow returned from the server (which could be lower than that requested from the client, for example if in the previous call you returned 200 total rows but in the meantime some row was deleted)
- the actual fetched list
I post here your classes adapted to support server-side paging, the dto class TestRecord and the class GwtRpcDataSource remain the same as yours
Bye!
Bit
Announcement
Collapse
No announcement yet.
X
-
smartgwt-extensions
Hi Nikolas,
Thank you.
Could you please replace SimpleGwtRPCDS.java with the latest one ?
Latest one has:
- correction to work with any component (suggestion by Isomorphic)
- added paging functionality example.
Aleksandras.
Leave a comment:
-
Very good work. I've added the classes to smartgwt-extensions :
http://code.google.com/p/smartgwt-ex...lient/gwtrpcds
Unit Tests:
http://code.google.com/p/smartgwt-ex.../gwtrpcds/test
Leave a comment:
-
Example of data source with paging.
Hi All,
As mnenchev requested I did some research about paging (BTW: I'm total newbie to SmartClient as well as to GWT - so everything to me is quite new).
Important thing to note: for paging to work correctly DSResponse.setTotalRows (Integer) has to be set. Here you have to provide total amount of matching records (not a size of returned list).
Please find an attached TestDataSource.java with paging example.
Aleksandras.Attached Files
Leave a comment:
-
This is my entry point:
public void onModuleLoad() {
ListGridField rowNum = new ListGridField("id", "Id");
rowNum.setWidth(65);
rowNum.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
return rowNum +"";
}
});
ListGridField mail = new ListGridField("email", 100);
final ListGrid listGrid = new ListGrid();
rootPanel.add(listGrid);
listGrid.setWidth100();
listGrid.setHeight100();
TestDataSource dataSource = new TestDataSource();
listGrid.setAutoFetchData(true);
listGrid.setDataSource(dataSource);
listGrid.setFields(rowNum, mail);
listGrid.setDataPageSize(10);
listGrid.fetchData();
listGrid.draw();
}
And this is what i have changed in the datasource:
public TestDataSource() {
DataSourceField field;
field = new DataSourceIntegerField("id", "id");
field.setPrimaryKey(true);
field.setRequired(false);
addField(field);
field = new DataSourceTextField("mail", "mail");
field.setRequired(true);
addField(field);
}
@Override
protected void executeFetch(final String requestId, final DSRequest request, final DSResponse response) {
int startRow = request.getStartRow();
int endRow = request.getEndRow();
String sortBy = request.getSortBy();
TestServiceAsync service = ServiceUtils.getTestServiceAsync();
service.fetch(startRow, endRow, sortBy, new AsyncCallback<List<TestRecord>>() {
public void onFailure(Throwable caught) {
response.setStatus(RPCResponse.STATUS_FAILURE);
processResponse(requestId, response);
}
public void onSuccess(List<TestRecord> result) {
ListGridRecord[] list = new ListGridRecord[result.size()];
for (int i = 0; i < list.length; i++) {
ListGridRecord record = new ListGridRecord();
copyValues(result.get(i), record);
list[i] = record;
}
response.setData(list);
processResponse(requestId, response);
}
});
}
The rpc is working fine(i tested it before).
Leave a comment:
-
sry i cant do that, my project is not very trivial, it is struts and i inject gwt entry point in some jsp. I cant run it in hosted mode, and every time i deploy it :).
So what i can tell you is that the server side method for fletching is called only once, no matter of start and end row.
Leave a comment:
-
Most probably it is not related to GWT-RPC but more to ListGrid.
What values do you get from request.getStartRow () and request.getEndRow () ?
Add this code to your application startup:
Code:if (!GWT.isScript()) { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); }
Code:SC.logWarn ("Start row:" + Integer.toString (request.getStartRow ())); SC.logWarn ("End row:" + request.getEndRow ().toString ()); SC.logWarn ("Sort by:" + request.getSortBy ());
Aleksandras.
Leave a comment:
-
Where is the problem?
Hi, Thank you this template is great. But i am having problems with listgrid. Every thing is exactly as yours and here is my listgrid:
public void onModuleLoad() {
ListGridField rowNum = new ListGridField("id", "Id");
rowNum.setWidth(65);
rowNum.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
return rowNum +"";
}
});
ListGridField mail = new ListGridField("email", 100);
final ListGrid listGrid = new ListGrid();
rootPanel.add(listGrid);
listGrid.setWidth100();
listGrid.setHeight100();
TestDataSource dataSource = new TestDataSource();
listGrid.setAutoFetchData(true);
listGrid.setDataSource(dataSource);
listGrid.setFields(rowNum, mail);
listGrid.draw();
}
I added args start and end row and sorting to the fletch method.
I use setAutoFletch(true) but it doesn't fletch any records. If i use listGrid getData() it loads me just the 'first page'. What am i missing? The example is exactly the same. My server side pagination is checked and working.
Leave a comment:
-
Just reacting tothe approach Alius has demonstrated has the advantage that paging could be implemented
Emmanuel
Leave a comment:
-
Updated example.
Hi Isomorphic,
Thank you for correction.
Problem is that there is no method getOldValues() in DSRequest class (in smartGWT).
For the time being I've written my own version of combining original values with changes.
Please find an updated version of TestDataSource.java
Hi Sanjiv,
I've written some code which can be added to DSRequest to address this issue.
If you will find it suitable - please add it to next release.
Code:/** * The original record without changes. * * @param oldValues Original record without changes. Default value is null */ public void setOldValues(ListGridRecord oldValues) { setAttribute("oldValues", oldValues); } /** * The original record without changes. * * * @return ListGridRecord * */ public ListGridRecord getOldValues() { JavaScriptObject oldValues = getAttributeAsJavaScriptObject ("oldValues"); return new ListGridRecord (oldValues); } /** * Returns record where changes are combined with original values. * * * @return ListGridRecord */ private ListGridRecord getEditedRecord () { // Retrieving values before edit JavaScriptObject oldValues = getAttributeAsJavaScriptObject ("oldValues"); // Creating new record for combining old values with changes ListGridRecord newRecord = new ListGridRecord (); // Copying properties from old record JSOHelper.apply (oldValues, newRecord.getJsObj ()); // Retrieving changed values JavaScriptObject data = getData (); // Apply changes JSOHelper.apply (data, newRecord.getJsObj ()); return newRecord; }
AleksandrasAttached Files
Leave a comment:
-
Nice job Alius. Just FYI, those APIs (dataProtocol:"clientCustom" and the processResponse() method) were added to SmartClient precisely to enable GWT-RPC integration, but Alius was faster in creating a sample than we were :)
Relative to the other recently posted approach for GWT-RPC integration, the approach Alius has demonstrated has the advantage that paging could be implemented if the GWT-RPC service supports it.
One thing to correct - in TestDataSource.java it's assumed that a grid is initiating the requests. It would be more correct to use dsRequest.getOldValues() to get the originally submitted values (works with any component).
Leave a comment:
-
You may not need to recompile/rebuild. use this hack:
setAttribute("dataProtocol", "clientCustom", false);
in DataSource.
-jason
Leave a comment:
Leave a comment: