My goal is to edit an Entity bean, convert it to json and put it in the url bar for the next place. This is how I planned to send arguments to my next activity. I was hoping to use the AutoBeanCodex.encode(messageBean).getPayload() functionality because it really works well and is the most efficient. The problem I am running into is that I have to edit the bean using a new context but when I send it to the next activity and try to decode the entities form the place I am getting an exception that the bean is already in use by another request. I was looking for a way to clear out a request context, setting it to null but nothing seems to free the beans from my RequestFactory singleton. I guess my real question is, is there a clean way in gwt to edit an entity, convert it to json and then convert it back using request factory. Would seem to be easy using Autobean but has not been
@AutoBeanFactory.Category(value = { EntityProxyCategory.class, ValueProxyCategory.class, BaseProxyCategory.class })
@AutoBeanFactory.NoWrap(EntityProxyId.class)
interface InputBeanFactory extends AutoBeanFactory {
AutoBean<InputCollectionProxy> inputs();
AutoBean<AnalyticsOperationInputProxy> input();
}
.....
@Override
public AnalyticsViewPlace getPlace(String token) {
HashMap<String, String> parameters = PlaceUtils.getParameterPairs(token);
Long analyticsTaskId = Long.parseLong(parameters.get("analyticsTaskId"));
ArrayList<AnalyticsOperationInputProxy> detatchedInputs = null;
AutoBean<InputCollectionProxy> bean = AutoBeanCodex.decode(factory, InputCollectionProxy.class, parameters.get("arguments"));
bean.setFrozen(false);
InputCollectionProxy inputCollection =
bean.as();
List<AnalyticsOperationInputProxy> inputs = inputCollection.getInputs();
if (inputs != null) {
detatchedInputs = new ArrayList<AnalyticsOperationInputProxy>();
for (AnalyticsOperationInputProxy inputBean : inputs) {
AutoBean<AnalyticsOperationInputProxy> opBean = AutoBeanUtils.getAutoBean(inputBean);
opBean.setFrozen(false);
AnalyticsOperationInputProxy input = opBean.as();
detatchedInputs.add(input);
}
}
return new DashboardPlace(analyticsTaskId, detatchedInputs);
}
// In my activity I have to clone the objects into a new request because of problems with bean already being edited. This seems clumsy and would like to figure out some kind of work around.
for (AnalyticsOperationInputProxy argument : arguments) {
if (argument instanceof UIUserInputModelProxy) {
UIUserInputModelProxy input = request.create(UIUserInputModelProxy.class);
input.setInputName(argument.getInputName());
input.setDefaultValue(((UIUserInputModelProxy) argument).getDefaultValue());
inputs.add(input);
} else if (argument instanceof UIDateInputModelProxy) {
UIDateInputModelProxy input = request.create(UIDateInputModelProxy.class);
input.setInputName(argument.getInputName());
input.setDefaultValue(((UIDateInputModelProxy)argument).getDefaultValue());
inputs.add(input);
} else if (argument instanceof UIComplexInputModelProxy) {
UIComplexInputModelProxy input = request.create(UIComplexInputModelProxy.class);
input.setInputName(argument.getInputName());
input.setInputs(new ArrayList<AnalyticsOperationInputProxy>());
processArguments(request, input.getInputs(),((UIComplexInputModelProxy)argument).getInputs());
inputs.add(input);
}
}