Tuesday, August 27, 2013

Re: use GwtCreateResource to provide text programatically

On Tuesday, August 27, 2013 10:57:51 AM UTC+2, Jordan Amar wrote:

I would like my uiBinder to use a ClientBundle which will provide some runtime customized labels. Kind of a TextResource but not from a text file !
I tried with GwtCreateResource but from the DevGuide it seems like it's not possible. Am I right ? (create() and name() are the only methods available) What I would like to achieve is something like this:

client bundle:

public interface MyWidgetResources extends ClientBundle {      GwtCreateResource<WidgetLabels> labels();        @Source("lol.css")      CssResource style();  }  

labels class:

public final class MyWidgetLabels {      public String title() {          return load("mywidget-title");      }        public String banner() {          return load("mywidget-banner");      }        private String load(String key) {          // load from external..      }  }  


<ui:with type="com.package.MyWidgetResources" field="res"/>    <gwt:SimplePanel>      <gwt:Label text="{res.labels.title}"></gwt:Label>      <gwt:Label text="{res.labels.banner}"></gwt:Label>  </gwt:SimplePanel>  

My code looks like this already but res.label.title does not work. I could try to first store a reference to res.labels.create but it seems like I can't access any methods of labels in my uiBinder.

Is there a solution for me ? Maybe with a custom ResourceGenerator ? In this case some more pointers would be welcomed because i didn't really catch how that worked...

Thanks !

<ui:with> will either pick the value from a @UiField(provided = true) or use GWT.create() to instantiate the class, so why not just using: <ui:with field="labels" class="com.example.MyWidgetLabels"/> and then {labels.title} ?

(note: improvements to the docs welcome: http://www.gwtproject.org/makinggwtbetter.html#webpage) 

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