2012-11-15 5 views
3

나는 다음과 같은 GWT 모듈이 : 나는 Buzz 인스턴스 FizzModule를 "주입"하고 싶은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. 
    } 
} 

합니다. 그러나 GWT 모듈에서 볼 수있는 모든 코드 예제에서는 생성자를 사용하지 않습니다. 대신, onModuleLoad() 메소드 내부에서 DI 메커니즘 (일반적으로 ClientFactory 또는 GIN)을 부트 스트랩합니다. GWT가 강제하는 것입니까, 아니면 클라이언트 측에로드되기 전에 모듈을 삽입 할 수 있습니까? 미리 감사드립니다!

답변

2

GWT는 항상 0 인수 생성자를 사용하여 모듈을 인스턴스화합니다.

은 (기술적으로, 나는 그것이 GWT.create() 그래서 당신은 연기 사용할 수있는 바인딩 규칙을 사용하여 생각하지만, 그것은 다시 아무 것도 변경하지 않을 것입니다. 그 인스턴스화 방법) Buzz 인스턴스에서 올 것 BTW

?

+0

내가 왜 내가 새로운 사람인지는 모릅니다. –

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(); 
     } 
    } 
} 
관련 문제