Posts Tagged ‘NicolasLeroux’
[DevoxxFR2012] — Rev:2, Add twitter handle
ALTER TABLE speaker ADD COLUMN twitter varchar(255);
These scripts run automatically on startup, supporting continuous delivery.
## RESTful API Development
James Ward constructs JSON endpoints:
public class ApiController extends Controller {
public Result speakers() {
List speakers = Speaker.find.all();
return ok(Json.toJson(speakers));
}
}
Play’s `Json.toJson` uses Jackson for serialization, with configuration in `application.conf`:
play.modules.enabled += “play.modules.reactivemongo.ReactiveMongoModule”
## Form Handling and Validation
Nicolas demonstrates form binding:
public class FormsController extends Controller {
static Form speakerForm = Form.form(Speaker.class);
public Result create() {
Form<Speaker> filled = speakerForm.bindFromRequest();
if (filled.hasErrors()) {
return badRequest(views.html.create.render(filled));
} else {
Speaker speaker = filled.get();
speaker.save();
return redirect(routes.Application.index());
}
}
}
HTML forms use Play’s template engine:
@form(routes.FormsController.create()) {
@inputText(speakerForm(“name”), ‘_label -> “Name”)
@inputText(speakerForm(“twitter”), ‘_label -> “Twitter”)
}
## Frontend Development with HTML5 and JavaScript
Guillaume Bort integrates Twitter Bootstrap and jQuery for responsive design, demonstrating real-time features with WebSockets:
public class StreamController extends Controller {
public WebSocket updates() {
return WebSocket.whenReady((in, out) -> {
// Push updates
});
}
}
## Cloud Deployment to Heroku
James Ward executes deployment:
heroku create devoxx-play-demo
git push heroku master
heroku addons:create heroku-postgresql
Play’s `Procfile` declares the startup command:
web: target/universal/stage/bin/conference-app -Dhttp.port=${PORT}
“`
Implications for Modern Web Development
The presenters conclude that Play 2.0’s integrated toolchain and cloud-ready architecture dramatically accelerate development cycles while producing applications that scale effortlessly in elastic environments.