Class AppController

java.lang.Object
org.javalite.activeweb.HttpSupport
org.javalite.activeweb.AppController
All Implemented Interfaces:
RequestAccess
Direct Known Subclasses:
AbstractLesscController, AbstractSASSController, SimpleController

public abstract class AppController extends HttpSupport
Subclass this class to create application controllers. A controller is a main component of a web application. Its main purpose in life is to process web requests.
Author:
Igor Polevoy
  • Constructor Details

    • AppController

      public AppController()
  • Method Details

    • render

      protected HttpSupport.RenderBuilder render(String template)
      Renders results with a template. This method is called from within an action execution. This call must be the last call in the action. All subsequent calls to assign values, render or respond will generate IllegalStateException.
      Parameters:
      template - - template name, can be "list" - for a view whose name is different than the name of this action, or "/another_controller/any_view" - this is a reference to a view from another controller. The format of this parameter should be either a single word or two words separated by slash: '/'. If this is a single word, than it is assumed that template belongs to current controller, if there is a slash used as a separator, then the first word is assumed to be a name of another controller.
      Returns:
      instance of HttpSupport.RenderBuilder, which is used to provide additional parameters.
    • render

      protected HttpSupport.RenderBuilder render()
      Use this method in order to override a layout, status code, and content type.
      Returns:
      instance of HttpSupport.RenderBuilder, which is used to provide additional parameters.
    • getLayout

      protected String getLayout()
      Returns a name for a default layout as provided in activeweb_defaults.properties file. Override this method in a sub-class. Value expected is a fully qualified name of a layout template. Example: "/custom/custom_layout"
      Returns:
      name of a layout for this controller and descendants if they do not override this method.
    • getContentType

      protected String getContentType()
      Returns hardcoded value "text/html". Override this method to set default content type to a different value across all actions in controller and its subclasses. This is a convenient method for building REST webservices. You can set this value once to "text/json", "text/xml" or whatever else you need.
      Returns:
      hardcoded value "text/html"
    • restful

      public boolean restful()
      Returns true if this controller is configured to be RESTful.
      Returns:
      true if this controller is restful, false if not.
    • restful

      public static <T extends AppController> boolean restful(Class<T> controllerClass)