Domanda

Our application uses GIN to instantiate its GWT Resource bundle dynamically. This is done to enable loading different stylesheets at runtime for different display modes. In general, this means that I can create the singleton instance of the resources using something like MyApp.ginjector.getResources() as opposed to the standard GWT.create(MyAppResources.class).

This works well for everything but UiBinder code. We have been using <ui:with ref="res" type="com.company.MyAppResources" /> and I would like the instance of MyAppResources to be created with GIN rather than GWT.create.

According to the GWT UiBinder docs, there are two ways to handle this. Either use a @UiField(provided=true) or a @UiFactory in the component. Both of these methods are undesirable because they require people on my team (including myself) to remember to put this boilerplate code into every widget. Worse, if the creation code is omitted, everything will still appear to work, since GWT.create will create an instance of our Resources, just not the one we want.

I am looking for a method of creating some sort of global @UiFactory method which all my components will use, which will delegate to GIN. Alternatively, some way of hooking into GWT.create for specific classes and having client-side runtime code create the instance would work as well, as I could then delegate the object creation to my static Ginjector.

È stato utile?

Soluzione

If you have a com.company.MyApp with a static field ginjector, then you can use:

<ui:import field="com.company.MyApp.ginjector" />

and then (assuming ginjector.getResources().style().foo() in Java):

<span class="{ginjector.getResources.style.foo}">
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top