Let's say we have a domain entity defined this way:
interface MyNode {
MyNode getParent();
void setParent(MyNode node);
List<MyNode> GetChildren();
void AddChild(MyNode node);
void RemoveChild(MyNode node);
String getText();
void setText(String text);
}
I'm trying to implement a GWT web-app to work with these entities. I'm using request factory and editors framework. And I'm having some problems for sure :-)
Since the request factory definitions are trivial, I won't post them here. I'd only say that all the stuff related with children is a set of InstanceRequest
s.
So, the problem #1
Let's say we want to have a navigator for the whole tree. The idea is, every time we only see one node and we can either navigate to its parent or to one of its children. We'd like this navigator to use editors framework, so we build editors like MyNodeEditor
and ChildrenListEditor
.
As far as I know, editors only directly applicable to bean-styled entities. So, as long as working with MyNode
text
property is fine, working with children
property (ChildrenListEditor
) requires instance request.
My solution is, make MyNodeEditor
to be a ValueAwareEditor
and when it gets its value set, it initiates an InstanceRequest
to get the list of child nodes. That list is then bound to ChildrenListEditor
.
Are there any easier solutions? I believe it's quite a basic scenario.
Problem #2
We now decide to make our MyNodeEditor
capable of editing. Bean-style properties are fine again, but what about children? Using the code mentioned in problem #1:
@Override public void setValue(MyNodeProxy value) {
...
requestFactory.myNodeRequest().getChildNodes().using(value).fire(new Receiver<List<MyNodeProxy>>() {
@Override public void onSuccess(List<MyNodeProxy> response) {
childrenDriver.display(response);
}
});
...
}
causes "Caused by: java.lang.IllegalArgumentException: Attempting to edit an EntityProxy previously edited by another RequestContext" because I'm having 2 different requests for the same entity here. I don't have access to RequestContext
I've constructed at MyNodeEditor
, so I'm constructing the new one and it fails. What's the right approach?
It'd be easier if you had a List<MyNodeProxy> getChildren()
property on MyNodeProxy
to access the children, rather than firing a distinct request.
You can access the RequestContext
you passed to the RequestFactoryEditorDriver
by implementing HasRequestContext
on your editor. But in that case it won't help you, as firing it (from within your editor) would freeze it and thus make it unusable for anything else (such as saving the node after flushing the editor driver). If you cannot add a getChidren
to your MyNodeProxy
, then I'd suggest getting the children's list before you edit the node in the editor driver (alternatively, you could use a request based on the node's ID, rather than passing the node instance as an argument, or as a using()
value, which is what's causing the error).