Preserve the state of the UI in RequestFactoryEditorDriver?

91 views
Skip to first unread message

-sowdri-

unread,
Sep 21, 2011, 3:19:50 AM9/21/11
to google-we...@googlegroups.com
Hi, 

I've SearchCriteriaView which is an Editor<SearchCriteriaProxy>, one the user clicks on 'Search', i fire the request to the server with the bound proxy. 

If the user has to search again, I create new Proxy using new RC and have to bind the new proxy and fire the new RC. Now the previous state is lost. 

To preserve the state: 

  1. Clone the values in the old proxy in the new proxy.  OR
  2. Use the same old proxy, and fire the same RC again. 
"I cant do both now"

How to come about this, right now I'm unable to preserve the search criteria. 

Any help is appreciated!

Thanks, 

Thomas Broyer

unread,
Sep 21, 2011, 5:25:55 AM9/21/11
to google-we...@googlegroups.com
You could:
  • maybe serialize/deserialize them with RequestFactory#getSerializer to clone them (I think we tried that and had issues with it though)
  • clone your proxies using an AutoBeanVisitor (create a new proxy, "visit" the old one –get its AutoBean using AutoBeanUtils–, and for each property, update the new one)
  • use AutoBeans instead of proxies with your Editor, and send the request as a String (using AutoBeanCodex's encode() and decode())
  • serialize/deserialize your proxies by your own means (and use that to clone them)
FWIW, we went for the latest, because we wanted something readable in our URLs (the serialization of the proxies is used in our places).

-sowdri-

unread,
Sep 21, 2011, 7:34:19 AM9/21/11
to google-we...@googlegroups.com
Thanks Thomas!

I like this idea:


>> clone your proxies using an AutoBeanVisitor (create a new proxy, "visit" the old one –get its AutoBean using AutoBeanUtils–, and for each property, update the new one)

Is it possible to use the proxy created using the above method as a parameter in the requestContext method? I tried this, and got an error saying that "trying to use proxy with null request context" (I dont exactly remember the error)

I would be nice to have this feature.

Thanks,  

-sowdri-

unread,
Sep 21, 2011, 7:41:01 AM9/21/11
to google-we...@googlegroups.com
Would it be possible to have a rc.copy(xxx) feature??

CustomerProxy new = rc1.create(CustomerProxy.class);

// modified by user action

CustomerProxy copy = rc2.clone(old); // this should be as good as created using rc2

Thanks,

Thomas Broyer

unread,
Sep 21, 2011, 9:18:17 AM9/21/11
to google-we...@googlegroups.com

-sowdri-

unread,
Sep 21, 2011, 9:30:50 AM9/21/11
to google-we...@googlegroups.com
This is exactly what I'm looking for, thanks!

As suggested, I've used AutobeanCodex to convert my proxy to json. And upon receiving it on the server side, I could re-create the Proxy using AutoBeanFactorySource. 

Now I've to convert the proxy to concrete type. 

// this works!
AppAutobeanFactory autobeanFactory = AutoBeanFactorySource.create(AppAutobeanFactory.class);

CampaignSearchCriteriaProxy proxy = AutoBeanCodex.decode(autobeanFactory,
CampaignSearchCriteriaProxy.class, json).as();

logger.info("@autobean @clientId " + proxy.getClientId());

// I tried this, but this fails (just got ValueCodex this by tracing RF Servlet)
SearchCampaignRequest searchCampaign = ValueCodex.decode(SearchCampaignRequest.class, AutoBeanCodex.encode(AutoBeanCodex.decode(autobeanFactory,
CampaignSearchCriteriaProxy.class, json)));

logger.info("@valuecodex @clientId " + searchCampaign.getClientId());

As a last piece of the solution I've got the following questions:
  1. How does GWT RF maps Proxy to Concrete Types on the server-side?
  2. Is it possible to use the class directly?

Thanks, 

Jeff Larsen

unread,
Sep 21, 2011, 9:45:55 AM9/21/11
to google-we...@googlegroups.com
I have use cases where I need to be able to clone proxies and use them in different request contexts.

Here is the code I've done to accomplish that 



    public static <T extends BaseProxy> T cloneProxyToNewContext(Class<T> clazz, T proxy,
            RequestContext context) {
        T newProxy = context.create(clazz);
        AutoBean<T> oldBean = AutoBeanUtils.getAutoBean(proxy);
        AutoBean<T> newBean = AutoBeanUtils.getAutoBean(newProxy);
        AutoBeanCodex.decodeInto(AutoBeanCodex.encode(oldBean), newBean);
        newBean.setFrozen(true);
        newProxy = newBean.as();
        context.edit(newProxy);
        return newProxy;

    }

Jeff Larsen

unread,
Sep 21, 2011, 9:49:42 AM9/21/11
to google-we...@googlegroups.com
The setFrozen(true) is really important if the proxy you're copying is being edited by a different request context. Without setting that flag, you'll get errors. 

the context.edit changes the state from frozen to not frozen. 

-sowdri-

unread,
Sep 21, 2011, 10:13:53 AM9/21/11
to google-we...@googlegroups.com
Hi Jeff, thank you so much for sharing the code! Even I've got a lot of use cases. Just that, they were TODOs so for.. 
Reply all
Reply to author
Forward
0 new messages