Class ViewControllers

java.lang.Object
com.codename1.backend.ViewControllers
All Implemented Interfaces:
HttpServer.Handler

public final class ViewControllers extends Object implements HttpServer.Handler

Routes answered without a controller method, as Spring's addRedirectViewController and addStatusController.

@Bean
HttpServer.Handler shortcuts() {
    return new ViewControllers()
            .redirect("/docs", "/docs/index.html")
            .status("/favicon.ico", 204);
}

Spring's addViewController("/", "home") -- a template rendered for a path -- has no counterpart: a view here is compiled into the controller method that returns it, so there is nothing to look a view name up in at run time. A one-line @GetMapping method returning the name does the same and keeps the template checked at build time.

  • Constructor Details

    • ViewControllers

      public ViewControllers()
  • Method Details

    • redirect

      public ViewControllers redirect(String path, String location)
      Answers path with a 302 to location.
      Parameters:
      path - the path, exactly
      location - where the client is sent; relative or absolute
      Returns:
      this
    • redirect

      public ViewControllers redirect(String path, String location, int status)
      Answers path with status (a 3xx) and location.
      Parameters:
      path - the path, exactly
      location - where the client is sent
      status - 301, 302, 303, 307 or 308
      Returns:
      this
    • status

      public ViewControllers status(String path, int status)
      Answers path with status and no body.
      Parameters:
      path - the path, exactly
      status - 100 to 599
      Returns:
      this
    • handle

      public HttpServer.Response handle(HttpServer.Request request)
      Specified by:
      handle in interface HttpServer.Handler