Monday, November 25, 2013

How to use interface CssResource in Utility class (GWT/ GWTP)?

I have

public interface MyResource extends ClientBundle{      @NotStrict      @Source("/myResource.css")      MyCssResource css();  }  public interface MyCssResource extends CssResource {        String gridEvenRow();        String gridOddRow();        .... more styling here....  }  


@UiField MyResource res;  @Inject      public TestView(final Binder binder) {          widget = binder.createAndBindUi(this);          res.css().ensureInjected();      }  

In, I can style Grid without any problem.

for (int i = 1; i < myGrid.getRowCount(); i++) {      if((i%2) == 0){            myGrid.getRowFormatter().addStyleName(i, getView().getRes().css().gridEvenRow());      }      else{            myGrid.getRowFormatter().addStyleName(i, getView().getRes().css().gridOddRow());      }  }  

But I don't want to repeat this code every time I initialize a Grid. So I want to put this code into a Utility class so that I can use it by just 1 line of code. Utility.formatGridOddEvenRow(myGrid);

Here is code in Utility

public class Utility {        public static MyResource res;      public Utility(){           res.css().ensureInjected();      }        public static void formatGridOddEvenRow(Grid grid){          for (int i = 1; i < grid.getRowCount(); i++) {              if((i%2) == 0){                  grid.getRowFormatter().addStyleName(i, res.css().gridEvenRow());              }              else{                  grid.getRowFormatter().addStyleName(i, res.css().gridOddRow());              }          }      }  }  

However, it got run-time error [ERROR] - Uncaught exception escaped ? or some kind of error i don't know.

so, How to use interface MyCssResource in Utility class (GWT/ GWTP)?

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment