【问题标题】:GWT UiBinder doesn't load the stylesheetGWT UiBinder 不加载样式表
【发布时间】:2010-03-12 11:07:26
【问题描述】:

我想使用 UiBinder 制作一个 GWT 小部件。所以我做了:

UserPanel.ui.xml 像这样:

<?xml version="1.0" encoding="UTF-8"?>
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui'>

    <ui:with field="res" type="com.example.resources.UserPanelResources"  />

    <g:VerticalPanel styleNames='{res.userpanel.main}'>
      ...some other widgets go here...
    </g:VerticalPanel>
</ui:UiBinder>

UserPanel.css 像这样:

.main {
    width: 1000px;
    background-color: #f9f9fa;
    padding: 15px 10px;
    font-family: "Georgia";
}

和 UserPanelResources.java 之类的:

public interface UserPanelResources extends ClientBundle {
    public interface UserPanelCss extends CssResource {
        String main();
    }

    @Source("css/userpanel.css")
    UserPanelCss userpanel();
}

所有文件和包都在它们的位置,因为一切都编译得很好。但是当我运行开发模式时,没有应用样式!我尝试了许多不同的方法,但仍然不起作用。

我注意到,在 HTML 中,VerticalPanel 被赋予了被 GWT 混淆的类名,但 CSS 并没有发送到浏览器 - 事实上,GWT 甚至不要求它。

我错过了什么吗?

【问题讨论】:

    标签: css gwt resources uibinder


    【解决方案1】:

    好的,我找到了解决方案。

    原来是没有注入的UserPanelCss。

    解决方案在 UserPanelResources,java 中:

    public interface UserPanelResources extends ClientBundle {
        public final static UserPanelResources INSTANCE = GWT.create(UserPanelResources.class)
    
        public interface UserPanelCss extends CssResource {
            String main();
        }
    
        @Source("css/userpanel.css")
        UserPanelCss userpanel();
    }
    

    在 UserPanel.java 类中添加:

    static {
        UserPanelResources.INSTANCE.userpanel().ensureInjected();  
    }
    

    【讨论】:

      【解决方案2】:

      对于仅在 UiBinder 文件中使用的 CSS 资源,我遇到了同样的问题。

      我在我的小部件构造函数中添加了一个 hack 来修复它。这是使用上述类名的等价物:

      @注入 用户面板(用户面板资源资源){ resources.userpanel().ensureInjected(); initWidget(BINDER.createAndBindUi(this)); ... }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-05
        相关资源
        最近更新 更多