Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to externalize HTML in GWT apps?

Tags:

java

html

gwt

What's the best way to externalize large quantities of HTML in a GWT app? We have a rather complicated GWT app of about 30 "pages"; each page has a sort of guide at the bottom that is several paragraphs of HTML markup. I'd like to externalize the HTML so that it can remain as "unescaped" as possible.

I know and understand how to use property files in GWT; that's certainly better than embedding the content in Java classes, but still kind of ugly for HTML (you need to backslashify everything, as well as escape quotes, etc.)

Normally this is the kind of thing you would put in a JSP, but I don't see any equivalent to that in GWT. I'm considering just writing a widget that will simply fetch the content from html files on the server and then add the text to an HTML widget. But it seems there ought to be a simpler way.

like image 984
Limbic System Avatar asked Apr 13 '09 14:04

Limbic System


2 Answers

I've used ClientBundle in a similar setting. I've created a package my.resources and put my HTML document and the following class there:

package my.resources;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;

public interface MyHtmlResources extends ClientBundle {
 public static final MyHtmlResources INSTANCE = GWT.create(MyHtmlResources.class);

 @Source("intro.html")
 public TextResource getIntroHtml();

}

Then I get the content of that file by calling the following from my GWT client code:

HTML htmlPanel = new HTML();
String html = MyHtmlResources.INSTANCE.getIntroHtml().getText();
htmlPanel.setHTML(html);

See http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html for further information.

like image 167
Futzilogik Avatar answered Sep 30 '22 15:09

Futzilogik


You can use some templating mechanism. Try FreeMarker or Velocity templates. You'll be having your HTML in files that will be retrieved by templating libraries. These files can be named with proper extensions, e.g. .html, .css, .js obsearvable on their own.

like image 20
Boris Pavlović Avatar answered Sep 30 '22 15:09

Boris Pavlović