2013-04-18 3 views
3

저는 꽤 오랫동안 ClientBundle과 CssResources를 사용해 왔지만 제 스타일이 여러 번 주입되는 것을 보았습니다. 내 손가락을 가리킬 수있는 한 가지는 너무 내 템플릿에 <ui:with field='resources' type='com.vf.client.resources.Resources' />을 사용한다는 것이고 내 의심은 이것이 내 clientBundle의 여러 복사본을 생성한다는 것입니다. 이 문제를 일으킬 수도있는 한 가지는 내 clientfactory에서 내보기를 캐싱하는 Ray Ryan의 개념을 사용하므로 일부보기가 DOM에 연결되기 전에 만들어 졌기 때문입니다. 필자의베이스 뷰에서는 리소스에 제공된 = true를 사용하여 UiBinder가 나를 위해 새 것을 생성하도록하지 않았습니다. 그래도 작동하지 않을 수도 있습니다. 나는 의심하고 Ui :와 함께 새로운 복사본을 만들고 제공된 사실을 무시하고 있습니다. Chrome과 Firebug에서 개발자 도구를 사용하여 두 가지 경우 모두 스타일을 여러 번 주입했습니다. 내 모든 UiBinder 템플릿에서 Resources 클래스를 제거하지 않고도이 문제를 해결하는 방법에 대한 확신이 없으므로 작업이 상당히 복잡해집니다. 어떤 아이디어라도 감사합니다.GWT, CssStyle을 여러 번 주입했습니다.

내가 공장/싱글 톤을 사용하고있다

/** 
* 
* @author chris 
*/ 
public abstract class ViewImpl extends Composite implements IView, RequiresResize { 

    @UiField(provided = true) 
    public final Resources resources; 

} 




public interface Resources extends ClientBundle, CellTable.Resources, CellList.Resources, DataGrid.Resources { 

    /** 
    * These are the obfuscated styles. 
    * 
    * @return 
    */ 
    @Source({ "default.css", "default-external.css"}) 
    public Style style(); 
} 

업데이트 그냥 하나를 만들고 확인합니다. 응용 프로그램이 시작될 때 ClientFactory 구현에서이 Resources ClientBundle을 만듭니다. 내 응용 프로그램을 시작할 때 나는 내 스타일에서 ensureEnjected를 호출하고 이후부터는 확실히 코드에서 호출되지 않습니다.

이것은 내 싱글온 요청 팩토리를 얻는 공장입니다. 내 인터페이스 안에 정적 초기화 프로그램을 사용했지만, 여러 스타일 문제를 해결하기 위해 잠시 뒤로 이동했습니다.

import com.google.gwt.core.client.GWT; 

public class ResourcesFactory { 

    private static Resources instance = null; 

    private ResourcesFactory() { 
    } 

    public static final Resources getResources() { 
     if (instance == null) { 
      instance = GWT.create(Resources.class); 
     } 

     return instance; 
    } 
} 

내 클라이언트 번들이 초기화되고 여기에 주입됩니다.

@Override 
    public void onModuleLoad() { 
     if (Window.Location.getParameterMap().containsKey("debug")) { 
      Window.alert("Remote Debugging will be enabled, see server log for debug information"); 
      RemoteDebugService.enable();  
     } 

     try { 
      clientFactory = ClientFactory.INSTANCE; 
      masterLayoutPanel = clientFactory.getMasterLayoutPanel(); 
     } catch (Exception e) { 
      logger.log(Level.SEVERE, "Unable to instantiate the ClientFactory", e); 
      Window.alert("SOMEBODY BROKE THE BUILD, add ?debug to the url to enable remote debugging" + e.getMessage()); 
     } 

     RootLayoutPanel.get().add(masterLayoutPanel); 
     StyleInjector.inject(clientFactory.getResources().style().getText()); 

     PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(clientFactory.getPlaceHistoryMapper()); 
     PlaceController placeController = clientFactory.getPlaceController(); 

     // Start PlaceHistoryHandler with our PlaceHistoryMapper 
     historyHandler.register(placeController, clientFactory.getEventBus(), defaultPlace); 

     startApplication(clientFactory, historyHandler); 
     } 

답변

0

나는 지금까지 잘못하고있는 한 가지 문제가 내 스타일을 여러 번 주입하게 만들었다는 것을 알아 냈습니다. 첫 번째는 내 CellTable 및 Datagrid 스타일을 단일 스타일 시트에 포함 시키도록 정의했지만이 스타일을 주입 할 때 여러 번 주입된다는 것입니다. 아래의 코드에서 default.css는 셀 테이블과 셀 격자 스타일을 포함하여 전체 웹 응용 프로그램에 대한 모든 CSS 정의를 포함합니다. 나는 응용 프로그램 시작시에 cellTableStyle()과 cell dataGridStyle()이 전체 스타일 시트를 삽입 할 때 이들을 주입했다.

public interface Resources extends ClientBundle, CellTable.Resources, CellList.Resources, DataGrid.Resources { 

... 

    /** 
    * {@link CellTable.Style} styles 
    */ 
    @Source("default.css") 
    Style cellTableStyle(); 

    /** 
    * {@link DataGrid.Style} styles 
    */ 
    @Source("default.css") 
    Style dataGridStyle(); 

    /** 
    * These are the obfuscated styles. 
    * 
    * @return 
    */ 
    @Source({ "default.css", "default-external.css" }) 
    public Style style(); 
... 


} 

만약 스타일 시트가 별도의 스타일 시트로 헤어 졌해야한다 이런 식으로 스타일을 선언하고 만 관련 스타일을 포함하거나 이러한 인터페이스를 구현하고 추가 의존하는 스타일 구현을 제거하는 내 주요 스타일을 구현합니다.

public interface Resources extends ClientBundle, CellTable.Resources, CellList.Resources, DataGrid.Resources { 

... 



    /** 
    * {@link CellTable.Style} styles 
    */ 
    @Source("celltable.css") 
    Style cellTableStyle(); 

    /** 
    * {@link DataGrid.Style} styles 
    */ 
    @Source("datagrid.css") 
    Style dataGridStyle(); 

    /** 
    * These are the obfuscated styles. 
    * 
    * @return 
    */ 
    @Source({ "default.css", "default-external.css" }) 
    public Style style(); 
... 


} 

이것은 스타일이 CellTable 스타일로 전달 될 수 있고 스타일이 한 번만 주입되는 구현입니다. 스타일은 필요한 모든 표, 표 및 목록 스타일을 의미합니다.

public interface Resources extends ClientBundle, CellTable.Resources, CellList.Resources, DataGrid.Resources { 

... 

public interface Style extends CssResource, ProgressWidget.Style, CellTable.Style, CellList.Style, DataGrid.Style { 
    ... 

} 


    /** 
    * Single style that can be used for all my cell table resources 
    * and the default styles. 
    * 
    * @return 
    */ 
    @Source({ "default.css", "default-external.css" }) 
    public Style style(); 
... 


} 
0

여러 번 주사하면 정확히 무엇을 의미합니까?

ClientBundle은 기본적으로 싱글 톤 (이 스레드 Will referring to a single ClientBundle class from multiple UiBinders cost anything? 참조)입니다.
provided=true을 사용해도 상관 없습니다.

하지만 당신은 정말 당신이 Gin를 사용할 수도 ClientBundle 프록시를하지 않으려는 또는 Factory 한 번 ClientBundle을 (@Inject를 통해 GWT.create 또는 마술를) 인스턴스화하고 Views에 주입하는하지만 난 그것을 원 컴파일 된 코드에 맞춰 경우 차이를 많이 내지 않는다.

관련 문제