Package com.oorian.html.js
Class SelectionApi
java.lang.Object
com.oorian.html.js.JavaScriptApi
com.oorian.html.js.SelectionApi
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears the current text selection in the document using the current page context.static voidclearSelection(HtmlPage page) Clears the current text selection in the document.static voidSets focus on the specified element using the current page context.static voidSets focus on the specified element.static voidSets focus on the element with the specified ID.static voidSets focus on the element with the specified ID using the current page context.static voidSelects all content in the document using the current page context.static voidSelects all content in the document.static voidselectAndFocus(Element element) Selects all text in the specified element and sets focus on it using the current page context.static voidselectAndFocus(HtmlPage page, Element element) Selects all text in the specified element and sets focus on it.static voidselectText(Element element) Selects all text in the specified element using the current page context.static voidselectText(HtmlPage page, Element element) Selects all text in the specified element.static voidselectText(HtmlPage page, String elementId) Selects all text in the element with the specified ID.static voidselectText(String elementId) Selects all text in the element with the specified ID using the current page context.
-
Constructor Details
-
SelectionApi
public SelectionApi()
-
-
Method Details
-
selectText
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
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
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
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
Sets focus on the specified element using the current page context.- Parameters:
element- The element to focus.
-
focus
Sets focus on the specified element.- Parameters:
page- The page containing the element.element- The element to focus.
-
focus
Sets focus on the element with the specified ID using the current page context.- Parameters:
elementId- The ID of the element to focus.
-
focus
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
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
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
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
Selects all content in the document.- Parameters:
page- The page to select all content on.
-