Class SelectionApi

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

public class SelectionApi extends JavaScriptApi
Provides text selection and focus functionality from server-side Java code.

This class wraps browser Selection and Focus APIs, allowing server-side code to programmatically select text in input elements and manage element focus.

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:


 // Select all text in an input field
 SelectionApi.selectText(myTextField);

 // Focus an element
 SelectionApi.focus(myButton);

 // Select all text and focus
 SelectionApi.selectAndFocus(myTextField);

 // Clear the current selection
 SelectionApi.clearSelection();
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • SelectionApi

      public SelectionApi()
  • Method Details

    • selectText

      public static void selectText(Element element)
      Selects all text in the specified element using the current page context.

      This is typically used with text input or textarea elements.

      Parameters:
      element - The element whose text should be selected.
    • selectText

      public static void selectText(HtmlPage page, Element element)
      Selects all text in the specified element.

      This is typically used with text input or textarea elements.

      Parameters:
      page - The page containing the element.
      element - The element whose text should be selected.
    • selectText

      public static void selectText(String elementId)
      Selects all text in the element with the specified ID using the current page context.
      Parameters:
      elementId - The ID of the element whose text should be selected.
    • selectText

      public static void selectText(HtmlPage page, String elementId)
      Selects all text in the element with the specified ID.
      Parameters:
      page - The page containing the element.
      elementId - The ID of the element whose text should be selected.
    • focus

      public static void focus(Element element)
      Sets focus on the specified element using the current page context.
      Parameters:
      element - The element to focus.
    • focus

      public static void focus(HtmlPage page, Element element)
      Sets focus on the specified element.
      Parameters:
      page - The page containing the element.
      element - The element to focus.
    • focus

      public static void focus(String elementId)
      Sets focus on the element with the specified ID using the current page context.
      Parameters:
      elementId - The ID of the element to focus.
    • focus

      public static void focus(HtmlPage page, String elementId)
      Sets focus on the element with the specified ID.
      Parameters:
      page - The page containing the element.
      elementId - The ID of the element to focus.
    • selectAndFocus

      public static void selectAndFocus(Element element)
      Selects all text in the specified element and sets focus on it using the current page context.
      Parameters:
      element - The element to select text in and focus.
    • selectAndFocus

      public static void selectAndFocus(HtmlPage page, Element element)
      Selects all text in the specified element and sets focus on it.
      Parameters:
      page - The page containing the element.
      element - The element to select text in and focus.
    • clearSelection

      public static void clearSelection()
      Clears the current text selection in the document using the current page context.
    • clearSelection

      public static void clearSelection(HtmlPage page)
      Clears the current text selection in the document.
      Parameters:
      page - The page to clear the selection on.
    • selectAll

      public static void selectAll()
      Selects all content in the document using the current page context.
    • selectAll

      public static void selectAll(HtmlPage page)
      Selects all content in the document.
      Parameters:
      page - The page to select all content on.