Class PageImpl

java.lang.Object
fc.web.page.PageImpl
All Implemented Interfaces:
Page

public class PageImpl extends Object implements Page
A superclass for generated pages. All pages derive from this class.
  • Field Details

    • log

      public Log log
      The default application log, retrieved via WebApp.getAppLog. All molly pages can use this variable directly, for example log.info("test"). The log output level (and hence whether a logging statement at that level will be seen) is set by the WebApp configuration file. (If WebApp is not used or configured, then the log level will be set to the Log.DEFAULT_LEVEL)
  • Constructor Details

  • Method Details

    • render

      public void render(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws Exception
      Specified by:
      render in interface Page
      Throws:
      Exception
    • init

      public void init(PageServlet servlet, String contextRelativePagePath) throws jakarta.servlet.ServletException
      Description copied from interface: Page
      This method is invoked whenever a page is created and before it is run.

      Pages should override this method to instantiate/set-up page variables as needed. (pages have no-arg constructors so like most of the servlet API, setup and initialization of variables is done in a init method instead).

      When overriding this class, you must remember to call: super.init

      The page class is reloaded if the page is modified. Variables should therefore be cleaned up in the

      invalid reference
      destory
      method as needed.
      Specified by:
      init in interface Page
      Throws:
      jakarta.servlet.ServletException
    • destroy

      public void destroy()
      Description copied from interface: Page
      This method is invoked whenever a page is destoryed/unloaded
      Specified by:
      destroy in interface Page
    • getPagePath

      public String getPagePath(jakarta.servlet.http.HttpServletRequest req)
      Description copied from interface: Page
      Returns the path to this page from the web servers document root.

      So for example, if the page is at foo/bar.mp and is running under the webapp context of context1, then the page path will be: /context1/foo/bar.mp. If there is no specific web app (i.e., the most common case of a default "" webapp), then the page path will be /foo/bar.mp

      This page path is essentially what needs to be typed in the browsers URL window to invoke the page. It's also useful as form action parameters. For example, in a molly page:

      ..
      <form action="[=getPagePath(req)]" method="post">
      ..
      </form>
      
      This will submit the form to the same page where the form is defined. This can be hard coded of course but by using getPagePath, the html does not have to be changed if the name of the page changes on disk.
      Specified by:
      getPagePath in interface Page
    • getRealPath

      public String getRealPath(jakarta.servlet.http.HttpServletRequest req)
      Description copied from interface: Page
      Returns the real absolute directory path for the PagePath.

      So, for example, for a webserver document root at /web/sites/default/ and a page located in foo/bar.mp, the real path will be: /web/sites/default/foo/bar.mp

      Specified by:
      getRealPath in interface Page
    • clientRedirect

      public void clientRedirect(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String newLocation) throws IOException
      Description copied from interface: Page
      Redirects the client to the new page location. This is a thin (possibly easier to remember) wrapper around the
      invalid reference
      HttpServletResponse.sendRedirect
      method.

      The location parameter can be relative to the specified request's URI or relative to the context root if it contains a leading '/'. The webapp name (if any) does not have to be specified, the redirect will creates a full URL (including the webapp context path) suitable for this purpose.

      For example:

      webapp context current page location parameter resulting page
      default web app ("/") foo/bar.mp baz.mp foo/baz.mp
      default web app ("/") foo/bar.mp /baz.mp baz.mp
      /myapp foo/bar.mp baz.mp /myapp/foo/baz.mp
      /myapp foo/bar.mp /baz.mp /myapp/baz.mp
      Specified by:
      clientRedirect in interface Page
      Parameters:
      req - the current request
      res - the current response
      Throws:
      IOException
    • getThreadLocalWriter

      Description copied from interface: Page
      Returns a thread specific CharArrayWriter that can be passed to this method as various points in the page. The contents of this writer can then be printed on the page when desired.

      Note: The writer is not reset or flushed when it is retrieved. It must be reset manually via calling the CharArrayWriter.reset() method. This design-decision allows request threads to collect debugging data across multiple pages.

      The suggested usage idiom is:

        dbg(true);
        CharArrayWriter cw = getThreadLocalWriter():
        bug(cw, "some message");
        ...
        bug(cw, "other message");
        ...
        
        cw.writeTo(out);
        cw.reset();
        
      
      Specified by:
      getThreadLocalWriter in interface Page
    • startTimer

      public final void startTimer()
      If set to true, a timer to calculate page render time is started after this method call. Page render time can then be displaying the value returned by invoking the getTime() method.
    • getTime

      public final long getTime()
      Returns the time elapsed after invoking
      invalid reference
      startTime
      method (in milliseconds)
    • dbg

      public final void dbg(boolean val)
      Starts/stop debugging with no dbg_prefix/dbg_suffix.
      Parameters:
      val - true to enable debugging, false to disable.
    • dbgPrefix

      public final void dbgPrefix(String dbg_prefix)
      Sets the prefix for debugging output.
      Parameters:
      dbg_prefix - some html/text (such as <font color=red>) that is printed before each debug statement
    • dbgSuffix

      public final void dbgSuffix(String dbg_suffix)
      Sets the suffix for debugging output.
      Parameters:
      dbg_suffix - some html/text that is printed after each debug statement
    • bug

      public final void bug(Writer writer, Object str1) throws IOException
      Prints a debug statement if debugging is turned on for this page.

      Typically the implicit page printwriter (the out variable) will be passed to this method and debug statements will be printed at the point where they are lexically invoked at the page.

      However, each page request thread can collect debugging information and print the output at some arbitrary location, such as the bottom of the page. The method getThreadLocalWriter() exists for this reason and can be used to collect thread-local output during page execution.

      Throws:
      IOException
    • bug

      public final void bug(Writer writer, Object str1, Object str2) throws IOException
      Throws:
      IOException
    • bug

      public final void bug(Writer writer, Object str1, Object str2, Object str3) throws IOException
      Throws:
      IOException
    • bug

      public final void bug(Writer writer, Object str1, Object str2, Object str3, Object... args) throws IOException
      Throws:
      IOException
    • debug

      public final void debug(Writer writer, Object str1) throws IOException
      Prints a debug statement if debugging is turned on for this page. Same as calling bug(Writer, Object).
      Throws:
      IOException
    • debug

      public final void debug(Writer writer, Object str1, Object str2) throws IOException
      Throws:
      IOException
    • debug

      public final void debug(Writer writer, Object str1, Object str2, Object str3) throws IOException
      Throws:
      IOException
    • debug

      public final void debug(Writer writer, Object str1, Object str2, Object str3, Object... args) throws IOException
      Throws:
      IOException