http://code.google.com/p/gwt-freezedry/
The general idea is it lets you store Objects/Graphs of IsSerializable
that are built at compile time or Page Request time to be available in
your GWT application.
Possible uses include:
1. You want to build a set of configuration classes at compile time
based on... something: compile environment, database values, etc.
2. You have an application that needs a big chunk of information from
a service before the user can even start using it. Embedding all this
information into the initial page-load saves the client from having to
make multiple requests back to to the server on startup, greatly
increasing startup time.
How it works:
You define an interface that extends Freezer with no-args methods
returning IsSerialiable objects:
ex:
package com.totsp.freezedry.example.client;
import com.totsp.gwt.freezedry.client.Freezer;
public interface ExampleFreezer extends Freezer {
public ExampleObject getObject();
}
You can now populate this in 2 ways: First, write an
[InterfaceName]Factory class with a no-args constructor that returns
objects. This will be invoked at compile time and the values returned
will become hard-coded into your final application:
package com.totsp.freezedry.example.client;
public class ExampleFreezerFactory implements ExampleFreezer {
public ExampleFreezerFactory() {
}
public ExampleObject getObject() {
ExampleObject o = new ExampleObject();
o.setMyLong(new Long(-2));
o.setMyString("This is a test.");
return o;
}
}
The other way is to provide a Dictionary (JavaScript variable) on the
page with the serialize values you wish the interface to return. This
is the behavior if no [InferfaceName]Factory class is found on the
classpath at compile time. The Dictionary variable should be named
with the FQN of your interface (replacing . with _), and attributes
named with the method name on the interface: For example, in a JSP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="com.totsp.freezedry.example.client.ExampleObject,
com.totsp.gwt.freezedry.server.SimpleSerializer,
java.net.URLEncoder" %>
<%
ExampleObject o = new ExampleObject();
o.setMyString( "This is a dictionary test");
o.setMyLong( new Long( 255 ));
%>
<html>
<head>
<title></title>
<script language='javascript'
src='com.totsp.freezedry.example.Example.nocache.js'></script>
<script language='javascript'>
var com_totsp_freezedry_example_client_ExampleFreezer = {
getObject: unescape(
"<%=URLEncoder.encode(
SimpleSerializer.serializeObject( o ),
"UTF-8" )%>" )
};
</script>
</head>
<body>
<iframe src="javascript:''" id='__gwt_historyFrame' style='width:
0;height:0;border:0'></iframe>
</body>
</html>
The SimpleSerializer class is included to make serializing your
objects from the server for this case a single method call.
Please note, because of changes to the serialization generators APIs,
this will only work with GWT 1.4 (build yer own).