저는 꽤 오랫동안 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);
}