Tuesday, November 26, 2013

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

In your MyResource put a 

public static final MyResource RESOURCES = GWT.create(MyResource.class);

and then use that resource in your Util class by MyResource.RESOURCES.css.style();

If you are using GWTP then I recommend a ResourceInjector that you can call in your BootstrapperImpl that will take care of all the ensureInjected()'s for you.

On Monday, November 25, 2013 8:48:59 PM UTC-6, Tom wrote:

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

in TestView.java

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

In TestPresenter.java, 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 google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment