33. HTML form submission data is easy to deal
with using the play.data.* package
Uses Spring data binder to wrap a model
(class)
34. To use:
public class User {
public String email;
public String password;
}
Form<User> userForm = form(User.class);
35. Now, you can create a User from a
hashmap or request object
Map<String,String> anyData = new HashMap();
anyData.put("email", "bob@gmail.com");
anyData.put("password", "secret");
User user = userForm.bind(anyData).get();
or
User user = userForm.bindFromRequest().get();
36. Can add constraints using JSR303
implementation
public class User {
@Required
public String email;
public String password;
public String validate() {
if(authenticate(email,password) == null) {
return "Invalid email or password";
}
return null;
}
}
37. Custom handling of errors when
invalid form submissions
if(userForm.hasErrors()) {
return badRequest(form.render(userForm));
} else {
User user = userForm.get();
return ok("Got user " + user);
}
45. By convention, the default database must be
called default.
Other databases can have custom names.
Only the h2 database driver is provided by
default. You'll have to manually configure any
other drivers as an application dependency.
46. EBean and Hibernate
Both Ebean and Hibernate are supported
Ebean is natively supported
Hibernate as an application dependency
47. Ebean
Enabled in the conf/application.conf file
***Play generates getter/setters to be available
at runtime, not compile time!***
51. Must manually denote a transaction
using @Transactional
@Transactional
public static Result index() {
...
}
52. Can retrieve current entity manager
using the play.db.jpa.JPA helper
class
public static Company findById(Long id) {
return JPA.em().find(Company.class, id);
}
59. sbt
Scala DSL
Uses build definition
Accurate incremental recompilation
Not all sbt features are included in Play
60. sbt build definition
Use := to set a setting
There are a number of default settings.
● Resovers
● Source
● Target
● Hooks for CoffeeScript, LESS, and
JavaScript minification and generation
64. Uses Maven2 and Scala Tools by default
You can add your own:
resolvers += (
"Local Repository" at "file://"+Path.userHome.
absolutePath+"/.m2/repository"
)
66. ● Play has its own authorization and
authentication
● No JAAS compatibility
● Only basic support, may not be enough for
enterprise apps
● There are a number of third party modules
that may provide the auth support you need.