3

私は次のGWTモジュールを持っています:

public class FizzModule implements EntryPoint {
    private Buzz buzz;

    public FizzModule() {
        this(null);
    }

    public FizzModule(Buzz bz) {
        super();

        setBuzz(bz);
    }

    @Override
    public void onModuleLoad() {
        // ...etc.
    }
}

FizzModuleインスタンスを「注入」したいと思いBuzzます。ただし、GWTモジュールで見られるすべてのコード例では、コンストラクターを使用していません。代わりに、メソッド内からDIメカニズム(通常はClientFactoryまたはGIN)をブートストラップしonModuleLoad()ます。これはGWTが強制するものですか、それともクライアント側にロードする前にモジュールを注入できますか?前もって感謝します!

4

2 に答える 2

2

GWTは、常にゼロ引数コンストラクターを使用してモジュールをインスタンス化します。

(技術的には、遅延バインディングルールを使用できるように使用していると思いGWT.create()ますが、インスタンス化の方法については何も変わりません)

ところで、Buzzインスタンスはどこから来るのでしょうか?

于 2012-11-15T16:14:30.663 に答える
0

URLにパラメーターを追加して、PlaceControllerを使用できます。次に、モジュールのロード時にこれらの値を取得します。

public void onModuleLoad() {
    SimplePanel mainPanel = new SimplePanel();
    EventBus eventBus = GWT.creat(EventBus.class);
    // Start ActivityManager for the main widget with ActivityMapper
    ActivityManager activityManager = new ActivityManager(injector.getActivityMapper(),
            eventBus);
    activityManager.setDisplay(mainPanel);
    RootPanel.get().add(mainPanel);

    // Start PlaceHistoryHandler with our PlaceHistoryMapper
    AppPlaceHistoryMapper contentHistoryMapper = GWT.create(AppPlaceHistoryMapper.class);
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(contentHistoryMapper);
    PlaceController placeController = new PlaceController(eventBus)
    historyHandler.register(placeController, injector.getEventBus(), new MainPlace());

    // Goes to the place represented on URL else default place
    historyHandler.handleCurrentHistory();
    if(placeController.getWhere() instanceof MainPlace) {
        (MainPlace).getFoo();
    }
}

public class MainPlace extends Place {

    private String foo;

    public MainPlace(String token) {
        String foo = token;
    }

    @Override
    public String getFoo() {
        return foo;
    }

    public static class Tokenizer implements PlaceTokenizer<MainPlace> {

        @Override
        public MainPlace getPlace(String token) {
            return new MainPlace(token);
        }

        @Override
        public String getToken(MainPlace place) {
            return place.getFoo();
        }
    }
}
于 2012-11-16T00:18:38.237 に答える