1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
    blackbox23 is on a distinguished road

      0  

    Default How to Send information back to the client using BasePagingLoadResult?

    How to Send information back to the client using BasePagingLoadResult?


    Hello,

    I hope someone can help me out on this.

    I've implemented a remote search using Paging and it works fine.

    However, I have a requirement wherein I would need to pass an information back to the client using the BasePagingLoadResult. Specifically I need to pass the value back to the client of the total size of the data list before it was filtered in the server. I can't use the totalLength because this is the totalLength of the filtered data.

    I can't seem to find an elegant solution to this other than subclassing BasePagingLoadResult with an Object like a PagingLoadConfig. Is this the only solution?


    Thanks!

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You can extend BasePagingLoadResult and add your own fields to it. Than you pass over your extended version over the wire.

  3. #3
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
    blackbox23 is on a distinguished road

      0  

    Default


    Okay. Thanks Sven.

  4. #4
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
    blackbox23 is on a distinguished road

      0  

    Default


    I tried extending BasePagingLoadResult, but I received SerializationException.

    I added a no-arg constructor but I could not explicitly call BasePagingLoadResult's default no-arg constructor because it is not visible, so I explicitly call another constructor instead, and it's working fine. Thanks


    Code:
    XBasePagingLoadResult() {
    		//workaround because BasePagingLoadResult() constructor is not visible
    		super(new ArrayList<Data>());
    	}

  5. #5
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Please post your full class and also the full exception

  6. #6
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
    blackbox23 is on a distinguished road

      0  

    Default


    Hi Sven,

    Here's my extension to BasePagingLoadResult (without a no-arg constructor):

    Code:
    public class TestBasePagingLoadResult<Data> extends BasePagingLoadResult<Data> implements Serializable {
    	private int unfilteredDataSize;
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = -3404898837876268698L;
    
    
    	public TestBasePagingLoadResult(List<Data> data) {
    		super(data);
    	}
    
    	public TestBasePagingLoadResult(List<Data> data, int offset, int totalLength) {
    		super(data, offset, totalLength);		
    	}
    
    	public void setUnfilteredDataSize(int unfilteredDataSize) {
    		this.unfilteredDataSize = unfilteredDataSize;
    	}
    
    	public int getUnfilteredDataSize() {
    		return this.unfilteredDataSize;
    	}
    }

    Here's the exception I got:

    Code:
    com.google.gwt.user.client.rpc.SerializationException:
    Type 'com.xxx.test.admin.common.extension.TestBasePagingLoadResult'
    was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded.
    For security purposes, this type will not be serialized.: instance = com.xxx.test.admin.common.extension.TestBasePagingLoadResult@4663bc
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:610)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:129)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:609)
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:467)

    This is the workaround I did which works fine:

    Code:
    public class TestBasePagingLoadResult<Data> extends BasePagingLoadResult<Data> implements Serializable {
    	private int unfilteredDataSize;
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = -3404898837876268698L;
    	
    	TestBasePagingLoadResult() {
    		//workaround because BasePagingLoadResult() constructor is not visible
    		super(new ArrayList<Data>());
    	}
    
    	public TestBasePagingLoadResult(List<Data> data) {
    		super(data);
    	}
    
    	public TestBasePagingLoadResult(List<Data> data, int offset, int totalLength) {
    		super(data, offset, totalLength);		
    	}
    
    	public void setUnfilteredDataSize(int unfilteredDataSize) {
    		this.unfilteredDataSize = unfilteredDataSize;
    	}
    
    	public int getUnfilteredDataSize() {
    		return this.unfilteredDataSize;
    	}
    }


    I don't know if this matters but here's my service and serviceImpl codes (Omitted some codes for brevity):

    1. Service Interface:

    Code:
    public interface TestsService extends RemoteService {
    	PagingLoadResult<Tests> getTestsForAutomatedTestDefinition(PagingLoadConfig config, int automatedTestDefinitionId);
    2. ServiceAsync

    Code:
    public interface TestsServiceAsync {
    	void getTestsForAutomatedTestDefinition(PagingLoadConfig config, int automatedTestDefinitionId, AsyncCallback<PagingLoadResult<Tests>> callback);
    3. ServiceImpl:

    Code:
    public class TestsServiceImpl extends RemoteServiceServlet implements TestsService {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = -7009686346178770259L;
    
    	
    	@SuppressWarnings("unchecked")
    	@Override
    	public PagingLoadResult<Tests> getTestsForAutomatedTestDefinition(PagingLoadConfig config, int automatedTestDefinitionId) {
    		final List<Tests> tests = (ArrayList<Tests>) getTestsService()....
    		final int unfilteredDataSize = tests.size();
    
    		//filtering here
    		:
    		:
    		
    
    		//sorting here
    		:
    		:
    		:
    
    		final int filteredSize = filtered.size();		
    
    		final ArrayList<Tests> sublist = new ArrayList<Tests>();
    		final int start = config.getOffset();
    		int limit = filteredSize;
    		if (config.getLimit() > 0) {
    			limit = Math.min(start + config.getLimit(), limit);
    		}
    
    		for (int i = start; i < limit; i++) {
    			sublist.add(filtered.get(i));		
    		}
    		
    
    		//Create the extended BasePagingLoadResult
    		final TestBasePagingLoadResult result = new TestBasePagingLoadResult(sublist, start, filteredSize);
    		result.setUnfilteredDataSize(unfilteredDataSize);
    		
    		return result;
    	}
    }

    Please let me know if there's any other possible solution to the above exception.

    Thanks!

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Posts
    8
    Vote Rating
    0
    ajaytushir is on a distinguished road

      0  

    Default


    Hi, I also need to send some information to the client side.
    I have implemented the server side code, but I am having issues in retrieveing the data at the client side.

    We are using the RpcProxy<PagingLoadResult<MyModel>>, and inside this, the service is being invoked, and this RPC proxy is being sent to the loader, so that the result data can be popultaed in the grid.
    As we are uisng the load() method inside this RPCProxy, we are not writing our own callback, and hence I am not implementing the onSuccess and onFailure method.

    So, in such case, what should I do to get the data that I set in my new class, that was implemented by extending BasePagingLoadResult.

    Thanks in advance.
    Ajay

  8. #8
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
    blackbox23 is on a distinguished road

      0  

    Default


    I'm not sure if I fully understand what you meant but we're using the information in the client side using the loader listeners like:


    Code:
    
    
    final
    
    LoadListener loadListener = new LoadListener() {
    public void loaderBeforeLoad(LoadEvent le) { final BasePagingLoadConfig config = le.<BasePagingLoadConfig> getConfig();
    **** }
    public void loaderLoad(LoadEvent le) { if (le.getData() instanceof TestBasePagingLoadResult<?>) { final TestBasePagingLoadResult<?> result = (TestBasePagingLoadResult<?>) le.getData();
    unfilteredDataSize = result.getUnfilteredDataSize(); } }
    public void loaderLoadException(LoadEvent le) { *********** } };
    this.loader.addLoadListener(loadListener);


Similar Threads

  1. How to send HTTP headers to client with ExtJS
    By DarkStarDS in forum Ext 3.x: Help & Discussion
    Replies: 10
    Last Post: 14 Sep 2009, 6:19 AM
  2. HttpProxy cannot send information via POST method
    By nhuyanhuk in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 2 Jun 2009, 10:08 PM
  3. Replies: 3
    Last Post: 22 Apr 2008, 12:26 PM
  4. how send tree node's information to server ?
    By hadikazemi in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 14 Feb 2008, 7:28 AM
  5. Send JSON back to server
    By oregontarheel in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 12 Apr 2007, 2:22 AM

Thread Participants: 2