public interface PathBindable<T extends PathBindable<T>>
T
that implements this class can be bound to/from a path parameter. The only requirement is
that the class provides a noarg constructor.
For example, the following type could be used to bind an Ebean user:
@Entity class User extends Model implements PathBindable<User> { public String email; public String name; public User bind(String key, String email) { User user = findByEmail(email); if (user != null) { user; } else { throw new IllegalArgumentException("User with email " + email + " not found"); } } public String unbind(String key) { return email; } public String javascriptUnbind() { return "function(k,v) {\n" + " return v.email;" + "}"; } // Other ebean methods here }Then, to match the URL
/user/[email protected]
, you could define the following route:
GET /user/:user controllers.Users.show(user: User)
Modifier and Type | Method and Description |
---|---|
T |
bind(java.lang.String key,
java.lang.String txt)
Bind an URL path parameter.
|
java.lang.String |
javascriptUnbind()
Javascript function to unbind in the Javascript router.
|
java.lang.String |
unbind(java.lang.String key)
Unbind a URL path parameter.
|
T bind(java.lang.String key, java.lang.String txt)
key
- Parameter keytxt
- The value as String (extracted from the URL path)java.lang.RuntimeException
- if this object could not be boundjava.lang.String unbind(java.lang.String key)
key
- Parameter keyjava.lang.String javascriptUnbind()