Tuesday, April 2, 2013

Re: How to embed HTML from TextResource using UiBinder

I found something that works, even though I think that should be possible with less glue code...

interface TextsBundle extends ClientBundle { @Source("text.txt") TextResource myText(); }

class SafeHtmlTexts {
  @Inject TextBundle texts;
  public SafeHtml myText() { return SafeHtmlUtils.fromSafeConstant(texts.myText().getText()); }
}

class ViewImpl {
  private final SafeHtmlTexts texts;
  @Inject public ViewImpl(..., SafeHtmlTexts texts) { this.texts = texts; ... }
  ...
  @UiFactory SafeHtmlTexts create() { return texts; }
}

ViewImpl.ui.xml:
  <ui:with field='texts' type='....SafeHtmlTexts'/>
  ...
  <div><ui:safehtml from="{texts.myText}"/></div>


--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment