【问题标题】:ui:with, style not showing upui:with,样式不显示
【发布时间】:2010-11-15 10:42:45
【问题描述】:

我想使用 .

在多个小部件之间共享一个 CSS。

我可以看到 css 类名被混淆了,但是类定义 当我检查 firefox / chrome 中的元素时没有出现。 这是我的代码。谁能建议我错过了什么?谢谢。

样式.css

.nameSpan {  color: #3E6D8E; background-color: #E0EAF1;} 

资源.java

public interface Resources extends ClientBundle { 
  @Source("Style.css") 
  Style style(); 
  public interface Style extends CssResource { 
    String nameSpan(); 
  } 
} 

uibinder.ui.xml

<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.my.app.widgets.logoname.Resources'/> 
  <g:HTMLPanel> 
      <div> 
        Well hello there 
        <g:InlineLabel ui:field='nameSpan' styleName="res.style.nameSpan">kevin</g:InlineLabel>
      </div> 
  </g:HTMLPanel> 
</ui:UiBinder> 

uibinder.class

public class uibinder extends Composite { 
        private static uibinderUiBinder uiBinder =     GWT.create(uibinderUiBinder.class); 
        interface uibinderUiBinder extends UiBinder<Widget, uibinder> {} 
        @UiField(provided = true)  final Resources res;  // the style doesn't show no matter provided=true is declared or not. 
        public uibinder(Resources res) { 
                res = GWT.create(Resources.class); 
                initWidget(uiBinder.createAndBindUi(this)); 
        } 

【问题讨论】:

  • 别忘了致电:res.style().ensureInjected();
  • 是的,这就是解决方案!!!谢谢。你应该把它作为答案,我会接受它!

标签: gwt uibinder


【解决方案1】:

你必须使用res.style().ensureInjected()

【讨论】:

  • 希尔布兰德已经提到过。但是,是的,这就是答案。
【解决方案2】:

您需要在某处指定样式(styleName 属性)。例如:

<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.my.app.widgets.logoname.Resources'/> 
    <g:HTMLPanel> 
        <div> 
            Well hello there 
            <g:InlineLabel ui:field='nameSpan' styleName="{res.nameSpan}">kevin</g:InlineLabel>
        </div> 
    </g:HTMLPanel> 
</ui:UiBinder>

您声明的属性ui:field 没有设置css 样式。它定义了要在uibinder 类中填写的属性。请参阅GWT doc 以获得一些指导。

【讨论】:

  • 事实上,我确实添加了 styleName,但没有显示样式。我已编辑问题以反映更改。
  • 在这种情况下,您可能需要检查 z00bs 的代码 sn-p 中的花括号是否也存在于您的代码中。
猜你喜欢
  • 2014-05-09
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多