PDA

View Full Version : Does TreeStore leaks @UiConstructor?



nomad
22 Oct 2011, 2:28 PM
I'm playing with the code borrowed from http://www.sencha.com/examples-dev/#ExamplePlace:basictree(uibinder) and I cannot resolve the following issue:

ERROR: com.sencha.gxt.data.shared.TreeStore has no default (zero args) constructor. To fix this, you can define a @UiFactory method on the UiBinder's owner, or annotate a constructor of TreeStore with @UiConstructor..
It looks like the generator ignores "provided = true" for "store" annotation. I tried to create @UiFactory method but it didn't help.
Is this a TreeStore code bug or did I forget to make some specific configuration actions?
(GWT 2.4, GXT 3.0d5, uibinder-bridge 2.4.0-SNAPSHOT)

Colin Alworth
22 Oct 2011, 5:00 PM
The code in that example is the actual code that compiles to produce the uibinder tree sample.


@UiField(provided = true)
TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());


<ui:with type="com.sencha.gxt.data.shared.TreeStore" field="store" />

Are the two relevant pieces of code. If provided=true is set for that field (make sure the fields have the same name!), UiBinder should not attempt to look for an alternate way of building the TreeStore. This is how this example and several others are working. This works with standard GWT 2.4.0 behavior, the uibinder-bridge jar is not required.

There is no plan to provide a @UiConstructor for TreeStore, as there is no good way to allow for a ModelKeyProvider instance that wouldn't make it just as easy to expose the store via a field. If you have suggestions in this area, we are open to them.

sven
22 Oct 2011, 5:04 PM
Also a Store is not really UI related and so should more be provided from the java code than getting create through the XML file.

nomad
23 Oct 2011, 1:37 PM
Thank you for the quick answer. The code was copied to a blank GWTP view with provided=true. I think the cause of this issue is somewhere outside the pasted code fragments. But I don't know where...

nomad
28 Oct 2011, 9:58 AM
I've found the what was caused the mistake:

public interface Binder extends UiBinder<Widget, MainView> {}
should be

public interface Binder extends UiBinder<Widget, MainViewImpl> {}
and uibinder-bridge dependency is required.
Thanks guys for your attention.

Colin Alworth
28 Oct 2011, 10:16 AM
Yes, uibinder-bridge will be required until the next version of GWT, which the changes in http://gwt-code-reviews.appspot.com/1524803/ should be included in.

lmcadory
30 May 2012, 9:00 AM
I'm still having this problem. I have everything right, but I still get the



ERROR: com.sencha.gxt.data.shared.TreeStore has no default (zero args) constructor. To fix this, you can define a @UiFactory method on the UiBinder's owner, or annotate a constructor of TreeStore with @UiConstructor..

I'm also trying to use the BoarderLayout UiBinder example with the BasicTree example. I'm using the @UiTemplate annotation, but that shouldn't effect anything right?

Colin Alworth
30 May 2012, 9:45 AM
TreeStore shouldn't have a @UiConstructor, as it requires a ModelKeyProvider instance. Create it in your java code before the createAndBind call, and set up the @UiField annotation on the TreeStore as provided = true as I mentioned in this post: http://www.sencha.com/forum/showthread.php?151902-Does-TreeStore-leaks-UiConstructor&p=663265&viewfull=1#post663265

lmcadory
30 May 2012, 10:57 AM
I did that. I copied it straight from the example:


class
KeyProvider implements
ModelKeyProvider<BaseDto> {
@Override
public String getKey(BaseDto item) {
return (item instanceof FolderDto ? "f-" : "m-") + item.getId().toString();
}
}

Colin Alworth
30 May 2012, 11:38 AM
This isn't an issue of how you define the model key provider, it is how you _create_ the treestore. The @UiField needs to look like this so UiBinder doesnt need to look for a @UiConstructor:


@UiField(provided = true)
TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());

Bolded parts are important, both creating the TreeStore instance in code and marking the TreeStore as being created in Java, not xml.

TreeStore should not be created in UiBinder XML, because it isn't a UI component.