guice - how to inject a uiBinder with @Inject (instead of GWT.create())? -
firstly, doing such thing practice ? tried seems right way me wasn't successful :
public class formviewimpl extends compositeview implements hasuihandlers<c>, formview { public interface settlementinstructionssearchformviewuibinder extends uibinder<widget, settlementinstructionssearchformviewimpl> {} @inject static formviewimpl uibinder; @inject static provider<dateeditorwidget> dateeditorprovider; @uifield(provided = true) mycomponent<string> mycomp; @uifield dateeditorwidget effectivedatefrom; // .. other fields @inject public formviewimpl () { mycomp = new mycomponent<string>("lol"); if (uibinder == null) uibinder = gwt.create(settlementinstructionssearchformviewuibinder.class); initwidget(uibinder.createandbindui(this)); } @uifactory dateeditorwidget createdateeditor() { return dateeditorprovider.get(); } }
what other things class no arguments required ? in company's project same kind of code works @ other place. sorry high level of noob here... if guys had pointers nice.
thanks
two issues:
first, 2 of @inject fields static - have done make static fields injected? static fields don't set when gin (or guice) creates new instances, have set once , done. static, never garbage collected - may okay you, or might problem, , should change them instance fields. if want keep them static, must invoke requeststaticinjection
in module ask gin initialize them when ginjector created.
next, if choose remove static, uibinder
field must still null in constructor, because fields can't have been injected yet! how set field on object haven't yet created? that's expecting gin able do. instead, consider passing argument @inject
decorated constructor. don't need save field, since widget use 1 time.
Comments
Post a Comment