开发者

ui:with, style not showing up

开发者 https://www.devze.com 2023-01-24 22:19 出处:网络
I would like to share a CSS across multiple widgets using . I can see that css class name are obfuscated but the class definition

I would like to share a CSS across multiple widgets using .

I can see that css class name are obfuscated but the class definition is not showing up when I inspect the element in firefox / chrome. Here're my codes. Can anyone suggest what am I missing? Thanks.

Style.css

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

Resources.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)  f开发者_开发百科inal 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)); 
        } 


You have to use res.style().ensureInjected()


You need to assign the style (styleName attribute) somewhere. For example:

<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>

The attribute ui:field you've declared does not set the css style. It defines the attribute that is to be filled in in your uibinder class. See the GWT doc for some guidance.

0

精彩评论

暂无评论...
验证码 换一张
取 消