hibernategwtrequestfactory

How to exclude a property when using the RequestFactory in GWT


I'am using the RequestFactory to retrieve a list of objects from the server. Now I want to exclude the "description" (String) property of the object which can contains a long text.

Is there any way to do that in RequestFactory at Runtime?

This is how I retrieve the list

    collectcontextProvider.get().getListObject().fire(
    new Receiver<List<ObjectProxy>>() {
    @Override
    public void onSuccess (List<ObjectProxy> objectList) {
        //display the list
        }           

        @Override
        public void onFailure(ServerFailure error) {
            //Error
          }
        });

I use Hibernate


Solution

  • Assuming you want the description field in other places of your app, you'll want a trimmed-down proxy that does not expose that property, and of course a service method that returns a list of such proxies.

    @ProxyFor(value=MyObject.class, locator=MyLocator.class)
    interface MyObjectLiteProxy extends EntityProxy {
       // all properties but 'description'
    }
    
    @ProxyFor(value=MyObject.class, locator=MyLocator.class)
    interface MyObjectProxy extend MyObjectLiteProxy {
       String getDescription();
    }
    
    @Service(MyService.class)
    interface CollectContext extends RequestContext {
       Request<List<MyObjectLiteProxy>> getListObjectLite();
    
       Request<List<MyObjectProxy>> getListObject();
    }
    

    Actually, you could even go farther and use the same MyService implementation for 2 RequestContexts:

    @Service(MyService.class)
    interface CollectLiteContext extends RequestContext {
       Request<List<MyObjectLiteProxy>> getListObject();
    }
    
    @Service(MyService.class)
    interface CollectContext extends RequestContext {
       Request<List<MyObjectProxy>> getListObject();
    }