Package play.mvc

Interface PathBindable<T extends PathBindable<T>>

  • public interface PathBindable<T extends PathBindable<T>>
    Binder for path parameters.

    Any type 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:

     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) {
             } 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;" +
         // Other ebean methods here
    Then, to match the URL /user/[email protected], you could define the following route:
     GET  /user/:user User)
    • Method Detail

      • bind

        T bind​(String key,
               String txt)
        Bind an URL path parameter.
        key - Parameter key
        txt - The value as String (extracted from the URL path)
        The object, may be this object
        RuntimeException - if this object could not be bound
      • unbind

        String unbind​(String key)
        Unbind a URL path parameter.
        key - Parameter key
        a suitable string representation of T for use in constructing a new URL path
      • javascriptUnbind

        String javascriptUnbind()
        Javascript function to unbind in the Javascript router.
        The javascript function, or null if you want to use the default implementation.