Search code examples
gwtuibinder

Can I use variables in UiBinder style definitions in GWT


In the following example, from a file MessageView.ui.xml:

<ui:style>
    .polite {
      position:fixed;
      background-color:notice-background-color;
      top:1em;
      left:2em;
      white-space:nowrap;
      border-radius:.5em;}
</ui:style>

<g:PopupPanel styleName="{style.polite}">
    <g:HTML ui:field="message">Message goes here.</g:HTML>
</g:PopupPanel>

can I define @notice-background-color such that other UiBinder files can also use the definition.


Solution

  • Yes you can. Define your color as static String:

    package com.myproject.client.resource;
    
    public class MyColors {
        public static String lightGreen = "#0bdc1a";
    }
    

    And define an @eval variable:

    <ui:style>
        @eval notice-background-color com.myproject.client.resource.MyColors.lightGreen;
    
        .polite {
          position:fixed;
          background-color:notice-background-color;
          top:1em;
          left:2em;
          white-space:nowrap;
          border-radius:.5em;}
    </ui:style>
    
    <g:PopupPanel styleName="{style.polite}">
        <g:HTML ui:field="message">Message goes here.</g:HTML>
    </g:PopupPanel>