Play GWT2 Module Version 1.8
Play GWT2 1.8 provides some classes and commands to simplify the integration of a GWT 2.x.x project/Module in a play application.
This module has been tested with play 1.2.3 and gwt 2.2.x and 2.3.x, but has not been tested yet with 2.4.0. If someone do it please, let me know.
New in version 1.8
* Rewrite play shell commands.
* add create new project --with gwt2.
* add Security lib (example will come in next version)
* fix lot of small bug.
p. New in version 1.7
* Add gwt2chat sample. This the Chat Sample from Play! 1.2 but GWT. 3 modules. refresh, long polling and websocket
* Add GWT2WSClient, a simple client to use with Play! Websocket.
* Add gwt.codesvr to url when in dev mode. Only for GET request. the plugin redirect the request with gwt.codesvr argument.
New in version 1.6
* Add GWT2SercieAsync annotation to define if a GWT2Service need to be invoked asyncron as aJob
* Add GWT2Chain concept to enable no async service to run Promise/Future/Job async with a callback. With this you can start as many future as you want without blocking the service thread
* Add new Async Sample
* Improve errors handling
* some bug fixes
h2. Start a new project
1. Create a new Play! application
> play new myGwt2App --with gwt2
2. Go to your application
> cd myGwt2App
Test you application:
play run
and in another terminal:
play gwt2:devmode
h2. Init a existing play project. Go to your application
> cd myApp
5. Edit
~# Application dependencies
~require:
~ - play
~ - play -> gwt2 1.8
6. Install GWT2 module.
> play install gwt2
TIPS: Skip the previous command if you want to install the module directly in the “modules” folder of your application.
p. 7. execute the next command to add the module to your play application
> play deps
h2. <a>Initialize you Application</a>
bc. play gwt2:init
this will
- create a folder in your application : myApp/app/gwt (directory for gwt modules)
- create a folder in your application : myApp/gwt-public (directory for GWT compiled resources)
- and copy gwt-user.jar to myApp/lib
- Add a default App.gwt.xml in your myApp
if you want to change get path for you gwt modules, edit the conf/application.conf file and add theese lines
then you can set you personal folder to use
if you want to manage the gwt-user.jar with play dependencies, add gwt-user to your play dependencies file.
~# Application dependencies
~require:
~ - play
~ - play -> gwt2 1.8
~ - com.google -> gwt-user 2.3.0
~ - com.google -> gwt-dev 2.3.0
Remove lib/gwt-user.jar and lib/gwt-dev.jar
> rm lib/gwt-user.jar
> rm lib/gwt-dev.jar
then run “play deps” again
> play deps
Update your route file
Update your route file to add gwt2 dynamic routing
* / module:gwt2
GWT2 configuration
if you want to change path for you gwt modules, edit the conf/application.conf file and add theese lines
# GWT2 Configuration
# ~~~~~
# gwt2.modulesdir=<modulesdir>
# it will be use to know where are gwt modules
# default: gwt
#
# gwt2.publicdir=<publicdir>
# it will be use to know where are the public directory for compiled module and for routing
# default: gwt-public
#
# gwt.publicpath=/<path>
# it will be use for routing configuration
# default: /app
#
# GWT devmode startupUrls
# #gwt2.devmode.url.auto=true
# gwt2.devmode.url.1=/
Create a GWT Module create your module like this:
play gwt2:create
this will ask you a gwt module name
What is the gwt module name ?
enter for eg: firstmodule
this action create some files
myApp/app/gwt/firstmodule
myApp/app/gwt/firstmodule/Firstmodule.gwt.xml (module)
myApp/app/gwt/firstmodule/public
myApp/app/gwt/firstmodule/public/index.html (default page for entry point)
myApp/app/gwt/firstmodule/client
myApp/app/gwt/firstmodule/client/Firstmodule.java (entry point)
myApp/app/gwt/firstmodule/client/GreetingService.java
myApp/app/gwt/firstmodule/client/GreetingServiceAsync.java
myApp/app/gwt/firstmodule/shared
myApp/app/gwt/firstmodule/shared/FieldVerifier.java
myApp/app/gwt/firstmodule/services
myApp/app/gwt/firstmodule/services/Greeting.java
GreetingService Interface must use annotation @RemoteServiceRelativePath(“greeting”)
Service Implementation must implements GWTService, be place in the package gwt.
Or if you want to place your service or name it differently, eg: GreetingServiceImpl.java, you must use @GWT2ServicePath(“/firstmodule/greet”) annotation
Testing you GWT Module with dev mode
First start you Play application.
play run
Then start the dev mode,
play gwt2:devmode
GWT will compile your modules at first time.
Now you access your gwt module this url
Compiling a module
To compile a module (eg: before deployment)
play gwt2:compile
this will ask you a gwt module name
What is the gwt module name ?
Enter a name, then GWT will compile your module.
Remove a GWT Module
As for creating a new GWT Module but use gwt2:remove
play gwt2:remove
this will ask you a gwt module name
What is the gwt module name ?
all directory of your module will be deleted:
- myApp/app/gwt/firstmodule/**
- myApp/gwt-public/firstmodule/**
Async
You can use @GWT2ServiceAsync to invoke your GWT2 service normaly or as a play job
Chain
If you don’t use @GWT2ServiceAsync you can use GWT2Chain in your GWT2Service to run Promise/Future/Job normaly or async with callback
for that you will use GWT2Service.chain(Future, GWT2Chain) for synced call (blocking thread) or GWT2Service.chainAsyn(Future, GWT2Chain) for async call (non blocking thread)
See gwt2async sample.
Debugging the GWT UI
1. The easiest way it to eclipsify, netbeansify, ... you application and then use you prefered IDE to use JPDA. By default GWT listen on port 3408.
Creating a service using GWT-RPC
this part is the same as the Play-GWT by Rustem Suniev.
If you follow the GWT manual, it will explain you how to expose a service with GWT-RPC using a RemoteServiceServlet.
Exposing a GWT service with Play is almost the same, but since you can’t define servlets in a Play application, you have to use the provided support class, play.modules.gwt.GWTService
For example, to implement this service:
package gwt.mymod.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("hello")
public interface HelloService extends RemoteService {
String sayHello(String name);
}
simply create a class that extends the play.modules.gwt.GWTService, and define the service URL path with the play.modules.gwt.GWTServicePath annotation. Like this:
package services;
import play.modules.gwt2.GWT2Service;
import play.modules.gwt2.GWT2ServicePath;
import gwt.mymod.client.HelloService;
@GWT2ServicePath("/main/hello")
public class HelloServiceImpl extends GWT2Service implements HelloService {
public String sayHello(String name) {
return "Hello " + name;
}
}
This is the only difference from the GWT documentation.
Using Play Model You can use Play Model directly with your GWT Services. For that you have 2 solutions.
1. the first one is to create JPA Entity without extending play.db.jpa.Model
@Entity
public class MyModel
{
@Required
@MinSize(1)
@MaxSize(100)
@Column(name="text", nullable=false, length=100)
public String someText;
}
You will have to use JPA.em().
2. the second one is to extends your model with play.db.jpa.Model and add a Custom Field Serializer side to the model class.
MyModel.java
@Entity
public class MyModel extends Model
{
@Required
@MinSize(1)
@MaxSize(100)
@Column(name="text", nullable=false, length=100)
public String someText;
}
MyModel_CustomFieldSerializer.java
public class MyModel_CustomFieldSerializer {
public static MyModel instantiate(SerializationStreamReader reader)
throws SerializationException {
return new MyModel();
}
public static void serialize(SerializationStreamWriter writer,
MyModel instance)
throws SerializationException {
writer.writeObject(instance.id);
writer.writeString(instance.someText);
}
public static void deserialize(SerializationStreamReader reader,
MyModel instance)
throws SerializationException {
instance.id = (Long) reader.readObject();
instance.someText = reader.readString();
}
Samples
You will find 2 samples in the folder “samples” in the play gwt2 modules.
1. simple test
This sample is just a basic gwt module create with:
- gwt2:init
- gwt2:create
- gwt2:compile
2. myModel
This sample is an basic gwt module wich use Play Model.
3. gwt2async
This sample show how to use async call inside a GWT2service doing long task without blocking any thread
to test any sample
a. cd> go to the sample folder
b. run> play deps
c. run> play gwt:compileall
d. run> play run
About
This Module is maintained by Vincent Buzzano
website:
- http://github.com/vbuzzano/play-gwt2