GIN binding problems in GWTP application - gwt

every one!
I'm having a compilation problem in my GWT app which is divided in 3 modules:
App-core: containing the main classes without an entry point,
App-A and App-B: inherit from App-core, and containing there specific classes with an entry point in each submodule.
I'm using GIN to inject classes instances in every module:
in App-core:
public interface App-coreGinjector extends Ginjector {
EventBus getEventBus();
Provider<LoginPagePresenter> getLoginPagePresenter();
...
}
App-coreModule extends AbstractPresenterModule {
protected void configureCore() {
install(new DefaultModule(App-corePlaceManager.class));
bindConstant().annotatedWith(DefaultPlace.class).to(LoginPagePresenter.NAME_TOKEN);
...
bind(AuthenticationManager.class).to(AuthenticationManagerImpl.class);
bindPresenter(LoginPagePresenter.class, LoginPagePresenter.MyView.class,
LoginPageView.class, LoginPagePresenter.MyProxy.class);
}
in App-A:
#GinModules({ App-AModule.class })
public interface App-AGinjector extends App-coreGinjector {
MyApp-AScreen getMyApp-AScreen();
...
}
public class App-AModule extends App-coreModule {
#Override
protected void configure() {
configureCore();
...
//Here we bind the App-A classes inheriting from App-core classes
bind(App-coreScreenManager.class).to(App-AcreenManager.class).in(Singleton.class);
...
//Here we bind the specific App=A classes
}
And we do the same thing in App-B
The maven compilation is successful for the App-A, but it fail for the App-B, with this message:
[ERROR] Errors in 'C:\workspace\App-core\client\gin\App-coreGinjectorImpl.java'
[ERROR] Line 790: Rebind result 'com.gwtplatform.mvp.client.proxy.PlaceManager' must be a class
[ERROR] Line 818: Rebind result 'lu.sfeir.grh.client.authentication.AuthenticationManager' must be a class
[ERROR] Line 1047: Rebind result 'lu.sfeir.grh.client.login.LoginPagePresenter.MyView' must be a class
[ERROR] Line 2359: Rebind result 'com.google.gwt.event.shared.EventBus' cannot be abstract
[ERROR] Cannot proceed due to previous errors
So the weird part int all this is that this error come from the shared module between these two submodules, witch is the binding of the LoginPagePresenter and the AuthentificationManager, but we have this compilation error just in one sub module.
So if someone had this king of problems I'm waiting for his precious help ^^
Ah! if you want some precisions , don't be shy!!

In GWTP 0.7 and all EventBus instances are changed from
com.google.gwt.event.shared.EventBus;
to
com.google.web.bindery.event.shared.EventBus
If you are using GWTP 0.6 you have to change them back...

Related

Why it still works without installing AndroidInjectionModule?

According to Dagger documentation about injecting activity objects, it says that installing AndroidInjectionModule in your application component. However, everything is fine without it.
Does it means that I don't need to declare it? Under what circumstances will it be wrong?
For example:
Injected instance
data class Food(val name: String)
Module
#Module
class FoodModule{
#Provides
fun provideFood(): Food {
return Food("cholocate")
}
}
BindingModule
#Module
abstract class MainActivityModule {
#ContributesAndroidInjector(modules = [FoodModule::class])
abstract fun FoodShop(): MainActivity
}
AppComponent (Without installing AndroidInjectionModule)
#Component(modules = [MainActivityModule::class])
interface AppComponent{
fun inject(app: App)
}
App
class App : Application(), HasActivityInjector {
#Inject
lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity>
override fun onCreate() {
super.onCreate()
DaggerAppComponent.create().inject(this)
}
override fun activityInjector(): AndroidInjector<Activity> {
return dispatchingActivityInjector
}
}
MainActivity
class MainActivity : AppCompatActivity() {
#Inject
lateinit var food: Food
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Log.d("test", "Get ${food.name}")
}
}
It get chocolate successfully in MainActivity.
Does it means that I don't need to declare it? Under what circumstances will it be wrong?
It actually seems like you don't need to declare it, but it might lead to compile errors if you don't.
If you have a look at AndroidInjectionModule you can see that it just lists a bunch of #Multibinds methods for framework types.
#Multibinds
abstract Map<Class<? extends Activity>, AndroidInjector.Factory<? extends Activity>>
activityInjectorFactories();
Now if you look up Declaring #Multibinds you can read that
You do not have to use #Multibinds for sets or maps that have at least one #IntoSet, #ElementsIntoSet, or #IntoMap binding, but you do have to declare them if they may be empty.
And to declare them if they may be empty is exactly what the AndroidInjectionModule module is doing for you. If the Android Injection parts would require an undefined Map of injector factories you would probably get a compile time error stating that it cannot be provided.
The reason that you don't need the module is because you're using #ContributesAndroidInjector, of which the generated code will contain a #Binds #IntoMap etc. method, that declares the bindings map. Stated above—as it is not empty anymore—you would not need the additional #Multibinds declaration that AndroidInjectionModule provides for the non-empty multibinding.
You might not need the module, but it will declare all the framework injector factories for you in case that they might be empty, possibly preventing one or two compile errors. After all the javadoc simply states that it should be installed, not that it must.
This module should be installed in the component that is used to inject the Application class.

Dagger 2 module dependency graph: bound multiple times

I'm new to Dagger 2, trying to port a (quite) complex application to it.
We have several dependencies on 'common' libraries (shared with other projects). Those 'common' libraries sometimes depend on other 'common' libraries. Each library exposes a module.
An example:
#Module
public class JsonModule {
#Provides
public Mapper provideMapper(ObjectMapper objectMapper) {
return new DefaultMapper(objectMapper);
}
#Provides
public ObjectMapper provideObjectMapper() {
return ObjectMapperFactory.build();
}
}
Our HttpModule depends on the JsonModule:
#Module(includes = {JsonModule.class})
public class HttpModule {
public HttpHelper provideHttpHelper(ObjectMapper objectMapper) {
return new DefaultHttpHelper(objectMapper);
}
}
Finally in my application, I depend on both these modules:
#Module(includes = {JsonModule.class, HttpModule.class})
public class MyAppModule {
public Service1 provideService1(ObjectMapper objectMapper) {
return new DefaultService1(objectMapper);
}
public Service2 provideService2(Mapper mappper) {
return new DefaultService2(mappper);
}
}
I then have 1 component that depends on my MyAppModule:
#Component(modules = MyAppModule.class)
#Singleton
public interface MyAppComponent {
public Service2 service2();
}
Unfortunately, when I compile the project, I get a Dagger compiler error:
[ERROR] com.company.json.Mapper is bound multiple times:
[ERROR] #Provides com.company.json.Mapper com.company.json.JsonModule.provideMapper(com.company.json.ObjectMapper)
[ERROR] #Provides com.company.json.Mapper com.company.json.JsonModule.provideMapper(com.company.json.ObjectMapper)
What am I doing wrong? Is it wrong to depend on a module twice in the same dependency graph?
In your MyAppModule you shouldn't include JsonModule, it is included by dagger implicitly. When including HttpModule dagger will automatically include all modules which HttpModule includes (in your case that is JsonModule).
It seems like the problem is related to our project's situation:
the common projects combine Groovy and Java
the common projects are built using Gradle
the application project combines Groovy and Java
the application project was built using Maven and the groovy-eclipse-compiler
Basicly: I blame the groovy-eclipse-compiler for now. I converted the project to Gradle, and everything works now.

Custom TabLayoutPanel in GWT

I'm trying to create my custom TabLayoutPanel extension, my code is following:
public class ExpandableTabLayoutPanel extends TabLayoutPanel {
#UiConstructor
public ExpandableTabLayoutPanel(double barHeight, Unit barUnit) {
super(barHeight, barUnit);
addExpandableBehaviour();
}
private addExpandableBehaviour(){
//...
}
}
And here I invoke it from UIBinder:
<a:ExpandableTabLayoutPanel barHeight="20" barUnit="PX">
<a:tab>
<a:header>header</a:header>
<a:AdvancedRichTextArea styleName="{style.area}" ui:field="area"/>
</a:tab>
</a:ExpandableTabLayoutPanel>
(I was forced by error messages to use a:tab/a:header instead of g:tab/g:header even if I don't have tab and header defined in my a: package/workspace, but that's probably not the issue)
If #UiConstructor annotation is present over ExpandableTabLayoutPanel like in the listing, I'm getting strange error:
[ERROR] [gwtreproduce] - <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> missing required attribute(s): arg1 barHeight Element <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> (:13)
When I disable #UiConstructor, I'm getting even stranger error:
[ERROR] [gwtreproduce] - Errors in 'generated://E6338B946DFB2D28988DA492134093C7/reproduce/client/TestView_TestViewUiBinderImpl.java' : [ERROR] [gwtreproduce] - Line 33: Type mismatch: cannot convert from TabLayoutPanel to ExpandableTabLayoutPanel
What am I doing wrong with extending TabLayoutPanel?
And side question: how it is possible that TabLayoutPanel constructor isn't annotated with #UiConstructor and can be used in UiBinder (how UiBinder knows which constructor to invoke)?
for you side question : you have to add (provided=true) to the UiField annotation of your widget. Then in the code, set the instance yourself, before createAndBindUi() call like this :
class Whaoo extends Composite{
/* with 'provided', UiBinder don't call any constructor */
#UiField(provided = true)
final Great foo;
interface WhaooUiBinder extends
UiBinder<Widget, Whaoo> {}
private static WhaooUiBinder uiBinder =
GWT.create(WhaooUiBinder.class);
public Whaoo() {
// initialize "provided" before createAndBindUi call
foo = new Great(String bar, int pouet);
initWidget(uiBinder.createAndBindUi(this));
}
}

google-gin a provider needs a dependency. NullPointerException BindingsProcessor.java:498

In my GWT application i'm trying to setup a DI mechanism wihich would allow me to have all the commonly necessary stuff at hand everywhere. I'm using google-gin which is an adaptation of guice for GWT. I have an injector interface defined as this:
#GinModules(InjectionClientModule.class)
public interface MyInjector extends Ginjector {
public PlaceController getPlaceController();
public Header getHeader();
public Footer getFooter();
public ContentPanel getContent();
public EventBus getEventBus();
public PlaceHistoryHandler getPlaceHistoryHandler();
}
My injection module is this:
public class InjectionClientModule extends AbstractGinModule {
public InjectionClientModule() {
super();
}
protected void configure() {
bind(Header.class).in(Singleton.class);
bind(Footer.class).in(Singleton.class);
bind(ContentPanel.class).in(Singleton.class);
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
bind(PlaceController.class).toProvider(PlaceControllerProvider.class).asEagerSingleton();
bind(PlaceHistoryHandler.class).toProvider(PlaceHistoryHandlerProvider.class).asEagerSingleton();
}
}
When calling MyInjector injector = GWT.create(MyInjector.class); i'm gettign the following exception:
java.lang.NullPointerException: null
at com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBinding(BindingsProcessor.java:498)
at com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBindingForUnresolved(BindingsProcessor.java:290)
at com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBindingsForUnresolved(BindingsProcessor.java:278)
at com.google.gwt.inject.rebind.BindingsProcessor.process(BindingsProcessor.java:240)
at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGeneratorImpl.java:76)
at com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator.java:47)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind(ShellModuleSpaceHost.java:141)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:585)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
The problem is that the PlaceController class actually depends on one of the other dependencies. I've implemented it's provider like this:
public class PlaceControllerProvider implements Provider<PlaceController> {
private final PlaceController placeController;
#Inject
public PlaceControllerProvider(EventBus eventBus) {
this.placeController = new PlaceController(eventBus);
}
#Override
public PlaceController get() {
return placeController;
}
}
what should i change for this to work?
Old question but having the same problem I kept falling here. I finally found the way to know which class is messing during ginjection.
When I launch my app in development mode and put stack to Trace, I noticed there is a step called : "Validating newly compiled units".
Under this, I had an error but I didn't notice it since I had to expand 2 nodes which weren't even in red color.
The error was "No source code available for type com.xxx.xxxx ...", which was due to a bad import on client side which couldn't be converted to Javascript.
Hope this may help other here !
While I'm not actually seeing how the errors you're getting are related to the PlaceController being injected, I do see that the provider is returning a singleton PlaceController even if the provider were not bound as an eager singleton or in a different scope. The correct way to write that provider would be:
public class PlaceControllerProvider implements Provider<PlaceController> {
private final EventBus eventBus;
#Inject
public PlaceControllerProvider(EventBus eventBus) {
this.eventBus = eventBus;
}
#Override
public PlaceController get() {
return new PlaceController(eventBus);
}
}
Let guice handle the scoping i.e. "Letting guice work for you".
Other than that, I almost bet that your problem is due to the use of asEagerSingleton. I recommend you try this with just in(Singleton.class) and I further posit that you didn't really need the singleton to be eager. It seems others had problems with the behavior too, there's some indication that it has to do with overusing asEagerSingleton or misunderstanding the #Singleton annotation in a few cases.
I also got a lot of NullPointerException warnings using GIN 1.x with no real explanation of what happened. When I upgraded to gin 2.0 I was told with high accuracy what the error was. You might be helped by upgrading to the 2.0 version that was released a year after you asked this question.
Had the same problem problem, same trace, and the error was that I used "server" classes in my "client" classes, so GIN can't find these classes.
I mean by "server" and "client" the packages in my project.
Hope this could help

GWT 2 CssResource how to

I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and my application compiled and worked fine. Now for GWT 2 I have created a ResourceBundle class and put all image sprites and CSS as follows:
public interface ResourceBundle extends ClientBundle {
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
#Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();
#Source("com/web/tech/public/stylesheet2.css")
public Css stylesheet2();
#Source("com/docobo/keswick/keswickweb/public/images/organisnew.gif")
public ImageResource add_org();
.....
}
The Css class is an empty class extending CssResource :
public interface Css extends CssResource{
}
Then in my onModuleLoad() I use :
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet1().getText());
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet2().getText());
When I compile I get the following error:
Rebinding com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle
Invoking <generate-with class='com.google.gwt.resources.rebind.context.InlineClientBundleGenerator'/>
Creating assignment for gxt_gray()
Replacing CSS class names
[ERROR] The following unobfuscated classes were present in a strict CssResource:
[ERROR] x-tab-scroller-left
[ERROR] x-tab-strip-disabled
[ERROR] ......loads of other styles
Fix by adding String accessor method(s) to the CssResource interface for obfuscated classes, or using an #external declaration for unobfuscated classes.
Following the above instruction when I use #external above all my style classes inside the CSS file I get the following error :
[ERROR] Generator 'com.google.gwt.resources.rebind.context.InlineClientBundleGenerator' threw threw an exception while rebinding 'com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle'
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
at java.lang.String.substring(Unknown Source)
at com.google.gwt.resources.css.GenerateCssAst$GenerationHandler.ignorableAtRule(GenerateCssAst.java:236)
at org.w3c.flute.parser.Parser.atRuleDeclaration(Parser.java:1178)
at org.w3c.flute.parser.Parser.ignoreStatement(Parser.java:622)
at org.w3c.flute.parser.Parser.parserUnit(Parser.java:452)
at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:107)
at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:119)
at com.google.gwt.resources.css.GenerateCssAst.exec(GenerateCssAst.java:663)
at com.google.gwt.resources.rg.CssResourceGenerator.prepare(CssResourceGenerator.java:506)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:531)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:502)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.generate(AbstractClientBundleGenerator.java:179)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:49)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:315)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:107)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.process(AbstractCompiler.java:161)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:84)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:196)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.access$300(AbstractCompiler.java:70)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:481)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:113)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:49)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:415)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:507)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:408)
at com.google.gwt.dev.Compiler.run(Compiler.java:194)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:89)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:83)
at com.google.gwt.dev.Compiler.main(Compiler.java:152)
Try with #NotStrict. Example:
#NotStrict
#Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();
Got it solved.
As pointed out by Thomas#Google Groups --> The #external must not be put "above" the style
http://code.google.com/p/google-web-toolkit/wiki/CssResource#External...
The example from this link, the css will look like :
#external .legacySelectorA, .legacySelectorB;
.obfuscated .legacySelectorA { .... }
.obfuscated .legacySelectorB { .... }
/* #external also accepts tail-globs */
#external .myProject-*;
.myProject-text {}
.myProject-foo {}