JavaScript is disabled on your browser.
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method
play.mvc

Interface QueryStringBindable<T extends QueryStringBindable<T>>



  • public interface QueryStringBindable<T extends QueryStringBindable<T>>
    Binder for query string parameters. Any type T that implements this class can be bound to/from query one or more query string parameters. The only requirement is that the class provides a noarg constructor. For example, the following type could be used to encode pagination:
     class Pager implements QueryStringBindable<Pager> {
     public int index;
     public int size;
     public Option<Pager> bind(String key, Map<String, String[]> data) {
     if (data.contains(key + ".index" && data.contains(key + ".size") {
     try {
     index = Integer.parseInt(data.get(key + ".index")[0]);
     size = Integer.parseInt(data.get(key + ".size")[0]);
     return Some(this);
     } catch (NumberFormatException e) {
     return None();
     }
     } else {
     return None();
     }
     }
     public String unbind(String key) {
     return key + ".index=" + index + "&" + key + ".size=" + size;
     }
     public String javascriptUnbind() {
     return "function(k,v) {\n" +
     " return encodeURIComponent(k+'.index')+'='+v.index+'&'+encodeURIComponent(k+'.size')+'='+v.size;\n" +
     "}";
     }
     }
     
    Then, to match the URL /foo?p.index=5&p.size=42, you could define the following route:
     GET /foo controllers.Application.foo(p: Pager)
     
    Of course, you could ignore the p key specified in the routes file and just use hard coded index and size parameters if you pleased.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      F.Option<T> bind (java.lang.String key, java.util.Map<java.lang.String,java.lang.String[]> data)
      Bind a query string parameter.
      java.lang.String javascriptUnbind ()
      Javascript function to unbind in the Javascript router.
      java.lang.String unbind (java.lang.String key)
      Unbind a query string parameter.
    • Method Detail

      • bind

        F.Option<T> bind(java.lang.String key,
         java.util.Map<java.lang.String,java.lang.String[]> data)
        Bind a query string parameter.
        Parameters:
        key - Parameter key
        data - The query string data
        Returns:
        An instance of this class (it could be this class) if the query string data can be bound to this type, or None if it couldn't.
      • unbind

        java.lang.String unbind(java.lang.String key)
        Unbind a query string parameter. This should return a query string fragment, in the form key=value[&key2=value2...].
        Parameters:
        key - Parameter key
      • javascriptUnbind

        java.lang.String javascriptUnbind()
        Javascript function to unbind in the Javascript router. If this bindable just represents a single value, you may return null to let the default implementation handle it.
  • Summary:
  • Nested |
  • Field |
  • Constr |
  • Method
  • Detail:
  • Field |
  • Constr |
  • Method

AltStyle によって変換されたページ (->オリジナル) /