View Full Version : How can I use HttpProxy to Paing grid with gxt 3.0

29 Mar 2012, 7:14 AM
How can I use HttpProxy to Paing grid, any idea?

Colin Alworth
29 Mar 2012, 8:25 AM
Start with the ideas in the paging grid example (which uses a grid, paging toolbar, and binds them to a ListStore and PagingLoader), and then wire the loader into an HttpProxy. The advanced combobox example shows how to use ScriptTagProxy, which has an API very similar to HttpProxy, but loads its data in a different way.


(http://sencha.com/examples-dev/#ExamplePlace:paginggrid)The basic idea when using these tools is that the Store and Loader should be used by your own application code and widgets, and the Loader should itself know about the DataReader and DataProxy, to see how it will load the data. At each level, these pieces should be interchangable - a Loader can work with any DataProxy (and possibly a DataReader) that can pull in the right kind of data for it, and then the PagingToolbar just needs to talk to the right kind of Loader.

4 Dec 2012, 3:26 PM
I extend HttpProxy and I added two helper methods like requestfactory

public interface MyAutoBeanFactory extends AutoBeanFactory {

AutoBean<FilterPagingLoadConfig> loadConfig();

AutoBean<SortInfo> getSortInfo();

AutoBean<FilterConfig> getFilterConfig();
The class

public class MyHttpProxy<C> extends HttpProxy<C> {

public MyHttpProxy(RequestBuilder builder) {

protected List<SortInfo> createRequestSortInfo(MyAutoBeanFactory factory, List<? extends SortInfo> original) {
List<SortInfo> sortInfo = new ArrayList<SortInfo>();

for (int i = 0; i < original.size(); i++) {
SortInfo originalSortInfo = original.get(i);
SortInfo reqSortInfo = factory.getSortInfo().as();

return sortInfo;

protected List<FilterConfig> createRequestFilterConfig(MyAutoBeanFactory factory, List<? extends FilterConfig> original) {
List<FilterConfig> sortInfo = new ArrayList<FilterConfig>();

for (int i = 0; i < original.size(); i++) {
FilterConfig originalSortInfo = original.get(i);
FilterConfig reqSortInfo = factory.getFilterConfig().as();



return sortInfo;



public interface UserProxy { String getFirst();
void setFirst(String first);
String getLast();
void setLast(String last);
String getLogin();
void setLogin(String login);
Long getId();
void setId(Long id);

public interface UserListProxy {
List<UserProxy> getData();
int getTotalCount();

public class UserJsonReader extends JsonReader<PagingLoadResult<UserProxy>, UserListProxy> {
public UserJsonReader(AutoBeanFactory factory,
Class<UserListProxy> rootBeanType) {
super(factory, rootBeanType);

protected PagingLoadResult<UserProxy> createReturnData(Object loadConfig, UserListProxy incomingData) {
FilterPagingLoadConfig pagingLoadConfig = (FilterPagingLoadConfig)loadConfig;

return new PagingLoadResultBean<UserProxy>(incomingData.getData(), incomingData.getTotalCount(), pagingLoadConfig.getOffset());


public interface AppAutoBeanFactory extends MyAutoBeanFactory {
AutoBean<UserListProxy> users();

final AppAutoBeanFactory factory = GWT.create(AppAutoBeanFactory.class);
UserJsonReader reader = new UserJsonReader(factory, UserListProxy.class);

String path = "users/users.php";
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path);
MyHttpProxy<FilterPagingLoadConfig> proxy = new MyHttpProxy<FilterPagingLoadConfig>(builder){
public void load(FilterPagingLoadConfig loadConfig,
Callback<String, Throwable> callback) {

List<SortInfo> sortInfo = createRequestSortInfo(factory, loadConfig.getSortInfo());

List<FilterConfig> filterConfig = createRequestFilterConfig(factory, loadConfig.getFilters());


super.load(loadConfig, callback);
//proxy.setWriter(new UrlEncodingWriter<FilterPagingLoadConfig>(factory, FilterPagingLoadConfig.class));
proxy.setWriter(new JsonWriter<FilterPagingLoadConfig>(factory, FilterPagingLoadConfig.class));

loader = new PagingLoader<FilterPagingLoadConfig, PagingLoadResult<UserProxy>>(proxy, reader){
protected FilterPagingLoadConfig newLoadConfig() {
return new FilterPagingLoadConfigBean();


UserProxyProperties props = GWT.create(UserProxyProperties.class);

store = new ListStore<UserProxy>(props.id());
loader.addLoadHandler(new LoadResultListStoreBinding<FilterPagingLoadConfig, UserProxy, PagingLoadResult<UserProxy>>(store));

I pasted only the relevant code.
The helper methods of MyHttpProxy is used because AutoBeans cannot send List