Results 1 to 8 of 8

Thread: How to Send information back to the client using BasePagingLoadResult?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
      0  

    Default 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
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    131
      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
      0  

    Default

    Okay. Thanks Sven.

  4. #4
    Sencha User
    Join Date
    Jan 2010
    Posts
    43
    Vote Rating
    0
      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
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    131
      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
      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!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •