Class NavigationApi

java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.NavigationApi

public class NavigationApi extends JavaScriptApi
Provides navigation and browser history functionality from server-side Java code.

This class wraps the browser's Navigation and History APIs, allowing server-side code to control page navigation, manipulate browser history, and perform redirects.

All methods are provided in two forms:

  • Convenience form - No page parameter; uses thread-local page lookup
  • Efficient form - Accepts page parameter; avoids thread-local lookup

Usage:


 // Navigate to a URL
 NavigationApi.navigateTo("/home");

 // Navigate back in history
 NavigationApi.back();

 // Push a new history state
 NavigationApi.pushState("New Page", "/new-url");

 // Efficient form when page reference is available
 NavigationApi.navigateTo(this, "/home");
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Navigates back one page in the browser history using the current page context.
    static void
    back(int pages)
    Navigates back the specified number of pages in the browser history using the current page context.
    static void
    back(HtmlPage page)
    Navigates back one page in the browser history.
    static void
    back(HtmlPage page, int pages)
    Navigates back the specified number of pages in the browser history.
    static void
    backAfterDelay(long delayMs)
    Navigates back in the browser history after a delay using the current page context.
    static void
    backAfterDelay(HtmlPage page, long delayMs)
    Navigates back in the browser history after a delay.
    static void
    Navigates forward one page in the browser history using the current page context.
    static void
    forward(int pages)
    Navigates forward the specified number of pages in the browser history using the current page context.
    static void
    Navigates forward one page in the browser history.
    static void
    forward(HtmlPage page, int pages)
    Navigates forward the specified number of pages in the browser history.
    static void
    go(int delta)
    Navigates the browser history by the specified delta using the current page context.
    static void
    go(HtmlPage page, int delta)
    Navigates the browser history by the specified delta.
    static void
    Navigates to the specified URL.
    static void
    Navigates to the specified URL using the current page context.
    static void
    navigateToAfterDelay(HtmlPage page, String url, long delayMs)
    Navigates to the specified URL after a delay.
    static void
    navigateToAfterDelay(String url, long delayMs)
    Navigates to the specified URL after a delay using the current page context.
    static void
    Navigates to the previous page in the browser history using the current page context.
    static void
    Navigates to the previous page in the browser history.
    static void
    Navigates to the referring page using the current page context.
    static void
    Navigates to the referring page.
    static void
    pushState(HtmlPage page, String title, String url)
    Pushes a new state onto the browser history stack.
    static void
    pushState(String title, String url)
    Pushes a new state onto the browser history stack using the current page context.
    static void
    Reloads the current page using the current page context.
    static void
    Reloads the current page.
    static void
    reloadAfterDelay(long delayMs)
    Reloads the page after a delay using the current page context.
    static void
    reloadAfterDelay(HtmlPage page, long delayMs)
    Reloads the page after a delay.
    static void
    replace(HtmlPage page, String url)
    Navigates to the specified URL without adding a history entry.
    static void
    Navigates to the specified URL without adding a history entry using the current page context.
    static void
    replaceState(HtmlPage page, String title, String url)
    Replaces the current state in the browser history.
    static void
    replaceState(String title, String url)
    Replaces the current state in the browser history using the current page context.
    static void
    setHash(HtmlPage page, String hash)
    Sets the URL hash (fragment identifier).
    static void
    Sets the URL hash (fragment identifier) using the current page context.

    Methods inherited from class com.oorian.html.js.JavaScriptApi

    executeJs, executeJs, executeJs, executeJs, getPage

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NavigationApi

      public NavigationApi()
  • Method Details

    • back

      public static void back()
      Navigates back one page in the browser history using the current page context.
    • back

      public static void back(HtmlPage page)
      Navigates back one page in the browser history.
      Parameters:
      page - The page initiating the navigation.
    • back

      public static void back(int pages)
      Navigates back the specified number of pages in the browser history using the current page context.
      Parameters:
      pages - The number of pages to navigate back.
    • back

      public static void back(HtmlPage page, int pages)
      Navigates back the specified number of pages in the browser history.
      Parameters:
      page - The page initiating the navigation.
      pages - The number of pages to navigate back.
    • forward

      public static void forward()
      Navigates forward one page in the browser history using the current page context.
    • forward

      public static void forward(HtmlPage page)
      Navigates forward one page in the browser history.
      Parameters:
      page - The page initiating the navigation.
    • forward

      public static void forward(int pages)
      Navigates forward the specified number of pages in the browser history using the current page context.
      Parameters:
      pages - The number of pages to navigate forward.
    • forward

      public static void forward(HtmlPage page, int pages)
      Navigates forward the specified number of pages in the browser history.
      Parameters:
      page - The page initiating the navigation.
      pages - The number of pages to navigate forward.
    • reload

      public static void reload()
      Reloads the current page using the current page context.
    • reload

      public static void reload(HtmlPage page)
      Reloads the current page.
      Parameters:
      page - The page to reload.
    • reloadAfterDelay

      public static void reloadAfterDelay(long delayMs)
      Reloads the page after a delay using the current page context.
      Parameters:
      delayMs - The delay in milliseconds before reloading.
    • reloadAfterDelay

      public static void reloadAfterDelay(HtmlPage page, long delayMs)
      Reloads the page after a delay.
      Parameters:
      page - The page to reload.
      delayMs - The delay in milliseconds before reloading.
    • backAfterDelay

      public static void backAfterDelay(long delayMs)
      Navigates back in the browser history after a delay using the current page context.
      Parameters:
      delayMs - The delay in milliseconds before navigating back.
    • backAfterDelay

      public static void backAfterDelay(HtmlPage page, long delayMs)
      Navigates back in the browser history after a delay.
      Parameters:
      page - The page initiating the navigation.
      delayMs - The delay in milliseconds before navigating back.
    • pushState

      public static void pushState(String title, String url)
      Pushes a new state onto the browser history stack using the current page context.
      Parameters:
      title - The title for the new history entry.
      url - The URL for the new history entry.
    • pushState

      public static void pushState(HtmlPage page, String title, String url)
      Pushes a new state onto the browser history stack.
      Parameters:
      page - The page initiating the history change.
      title - The title for the new history entry.
      url - The URL for the new history entry.
    • replaceState

      public static void replaceState(String title, String url)
      Replaces the current state in the browser history using the current page context.
      Parameters:
      title - The title for the history entry.
      url - The URL for the history entry.
    • replaceState

      public static void replaceState(HtmlPage page, String title, String url)
      Replaces the current state in the browser history.
      Parameters:
      page - The page initiating the history change.
      title - The title for the history entry.
      url - The URL for the history entry.
    • go

      public static void go(int delta)
      Navigates the browser history by the specified delta using the current page context.

      Positive values navigate forward, negative values navigate back.

      Parameters:
      delta - The number of history entries to traverse (positive = forward, negative = back).
    • go

      public static void go(HtmlPage page, int delta)
      Navigates the browser history by the specified delta.

      Positive values navigate forward, negative values navigate back.

      Parameters:
      page - The page initiating the navigation.
      delta - The number of history entries to traverse (positive = forward, negative = back).
    • setHash

      public static void setHash(String hash)
      Sets the URL hash (fragment identifier) using the current page context.

      This is useful for SPA-style navigation without triggering a page reload.

      Parameters:
      hash - The hash value to set (with or without the leading '#').
    • setHash

      public static void setHash(HtmlPage page, String hash)
      Sets the URL hash (fragment identifier).

      This is useful for SPA-style navigation without triggering a page reload.

      Parameters:
      page - The page to set the hash on.
      hash - The hash value to set (with or without the leading '#').
    • replace

      public static void replace(String url)
      Navigates to the specified URL without adding a history entry using the current page context.

      Unlike navigateTo(String), this method replaces the current history entry rather than creating a new one, so the user cannot navigate back to the current page.

      Parameters:
      url - The URL to navigate to.
    • replace

      public static void replace(HtmlPage page, String url)
      Navigates to the specified URL without adding a history entry.

      Unlike navigateTo(HtmlPage, String), this method replaces the current history entry rather than creating a new one, so the user cannot navigate back to the current page.

      Parameters:
      page - The page initiating the navigation.
      url - The URL to navigate to.