-
-
Notifications
You must be signed in to change notification settings - Fork 8
TLGwtSupport
GwtSupport is a base class that provides the capability to embed GWT interfaces as components in your Tapestry application, including component parameter passing and SmartGWT integration. In addition, the Library provides support for GWT "forever" caching and support for GWT-RPC integration with Tapestry. In combination with Security module, even the authentication is taken care of withing GWT-RPC
In order to use a GWT component on a Tapestry page, make your component extend the GwtSupport class. Override the following methods: getEntryPoint() and getModuleName(). You can also optionally override getGWTParameters() to pass your component parameters into the GWT module.
Since Tapestry versions all application assets automatically, GwtSupport can cache all GWT assets forever in production mode. This is done with GwtCachingFilter. It is configured to properly cache all stock GWT files correctly.
GWT modules frequently call other parts of the Web app, be it through GWT-RPC or other methods. Tapestry ordinarily interferes with this because it will prepend versioned asset paths to all calls and URLs. This is undesirable. GwtSupport automatically prevents this by loading GWT modules from it's original paths, stripping out Tapestry asset prefix, where necessary.
Some GWT modules require a JavaScript configuration statements included on the page before the GWT JavaScript code. GwtSupport supports this. You can override getJavaScriptInitialization(), which returns a list of Strings, to return statements to put on the page before the main GWT code. In the sample below, as part of SmartGWT integration, isomorphicDir variable is set.
GwtSupport exports the following Tapestry @Symbols:
- GwtCachingFilter.Symbols.NEVER_CACHE
List of extensions, separated by space, comma, or semicolon, that are never to be cached
- GwtCachingFilter.Symbols.NEVER_EXPIRE
List of extensions, separated by space, comma, or semicolon, that are cached forever Default is .cache.html for GWT
Here is an example of a GWT table component:
public class GwtTable extends GwtSupport
{
@Override
protected String getModuleName()
{
return "com.baw.website.gwt.table";
}
@Override
protected Class<?> getEntryPoint()
{
return TableEntryPoint.class;
}
@Override
protected List<String> getGWTParameters()
{
List<String> rv = new ArrayList<String>();
rv.add(variant);
rv.add(datasource);
return rv;
}
@Override
protected List<String> getJavaScriptInitialization()
{
final String modulePathValue = String.format("%s/sc/", getGwtModulePath());
return Lists.newArrayList(String.format("var isomorphicDir = \"%s\";", modulePathValue));
}
private @Getter @Parameter(required=true, defaultPrefix=BindingConstants.LITERAL) String datasource;
private @Getter @Parameter(required=false, value="JPA", defaultPrefix=BindingConstants.LITERAL) String variant;
}
And the accompanying GWT module code:
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TableEntryPoint implements EntryPoint
{
@Override
public void onModuleLoad()
{
// Find all the instances in this DOM where this entry point should be
// created.
// The dictionary is created by
Dictionary gwtComponents = null;
try
{
gwtComponents = Dictionary.getDictionary("gwtComponents");
} catch(MissingResourceException e)
{
// intentionally left blank
}
if (gwtComponents != null)
{
for (String str : gwtComponents.get(getClass().getName()).split(","))
{
buildInterface(str.split("\\|"));
}
}
else
{
buildInterface(null);
}
}
/**
* @wbp.parser.entryPoint
*/
private void buildInterface(String[] args)
{
RootPanel rootPanel = RootPanel.get();
if(args != null)
{
rootPanel = RootPanel.get(args[0]);
}
else
{
args = new String[] { "<none>" };
}
buildTable(rootPanel, args);
}