public class Page extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static interface |
Page.ExecutionCanceler
Deprecated.
superseded by
PendingJavaScriptResult |
static interface |
Page.ExtendedClientDetailsReceiver
Callback for receiving extended client-side details.
|
Constructor and Description |
---|
Page(UI ui)
Creates a page instance for the given UI.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addBrowserWindowResizeListener(BrowserWindowResizeListener resizeListener)
Adds a new
BrowserWindowResizeListener to this UI. |
void |
addDynamicImport(String expression)
Adds a dynamic import using a JavaScript
expression which is
supposed to return a JavaScript Promise . |
void |
addHtmlImport(String url)
In compatibility mode (or Flow 1.x), adds the given HTML import to the
page and ensures that it is loaded successfully.
|
void |
addHtmlImport(String url,
LoadMode loadMode)
In compatibility mode (or Flow 1.x), adds the given HTML import to the
page and ensures that it is loaded successfully.
|
void |
addJavaScript(String url)
Adds the given JavaScript to the page and ensures that it is loaded
successfully.
|
void |
addJavaScript(String url,
LoadMode loadMode)
Adds the given JavaScript to the page and ensures that it is loaded
successfully.
|
void |
addJsModule(String url)
Adds the given external JavaScript module to the page and ensures that it
is loaded successfully.
|
void |
addJsModule(String url,
LoadMode loadMode)
Deprecated.
LoadMode is not functional with external JavaScript
modules, as those are loaded as deferred due to
type=module in scrip tag. Use
addJsModule(String) instead. |
void |
addStyleSheet(String url)
Adds the given style sheet to the page and ensures that it is loaded
successfully.
|
void |
addStyleSheet(String url,
LoadMode loadMode)
Adds the given style sheet to the page and ensures that it is loaded
successfully.
|
Page.ExecutionCanceler |
executeJavaScript(String expression,
Serializable... parameters)
Deprecated.
Use
executeJs(String,Serializable...) instead since
it also allows getting return value back. |
PendingJavaScriptResult |
executeJs(String expression,
Serializable... parameters)
Asynchronously runs the given JavaScript expression in the browser.
|
void |
fetchCurrentURL(SerializableConsumer<URL> callback)
Retrieves the current url from the browser.
|
History |
getHistory()
Gets a representation of
window.history for this page. |
void |
open(String url)
Opens the given url in a new tab.
|
void |
open(String url,
String windowName)
Opens the given URL in a window with the given name.
|
void |
reload()
Reloads the page in the browser.
|
void |
retrieveExtendedClientDetails(Page.ExtendedClientDetailsReceiver receiver)
Obtain extended client side details, such as time screen and time zone
information, via callback.
|
void |
setLocation(String uri)
Navigates this page to the given URI.
|
void |
setLocation(URI uri)
Navigates this page to the given URI.
|
void |
setTitle(String title)
Sets the page title.
|
public Page(UI ui)
ui
- the UI that this page instance is connected topublic void setTitle(String title)
To clear the page title, use an empty string.
title
- the page title to set, not null
public void addStyleSheet(String url)
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
For component related style sheet dependencies, you should use the
@StyleSheet
annotation.
Is is guaranteed that style sheet will be loaded before the first page
load. For more options, refer to addStyleSheet(String, LoadMode)
url
- the URL to load the style sheet from, not null
public void addStyleSheet(String url, LoadMode loadMode)
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
For component related style sheet dependencies, you should use the
@StyleSheet
annotation.
url
- the URL to load the style sheet from, not null
loadMode
- determines dependency load mode, refer to LoadMode
for
detailspublic void addJavaScript(String url)
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
For component related JavaScript dependencies, you should use the
@JavaScript
annotation.
Is is guaranteed that script will be loaded before the first page load.
For more options, refer to addJavaScript(String, LoadMode)
url
- the URL to load the JavaScript from, not null
public void addJavaScript(String url, LoadMode loadMode)
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
For component related JavaScript dependencies, you should use the
@JavaScript
annotation.
url
- the URL to load the JavaScript from, not null
loadMode
- determines dependency load mode, refer to LoadMode
for
detailspublic void addJsModule(String url)
If the JavaScript modules do not need to be added dynamically, you should
use the @JsModule
annotation instead.
url
- the URL to load the JavaScript module from, not
null
@Deprecated public void addJsModule(String url, LoadMode loadMode)
LoadMode
is not functional with external JavaScript
modules, as those are loaded as deferred due to
type=module
in scrip
tag. Use
addJsModule(String)
instead.
If the JavaScript modules do not need to be added dynamically, you should
use the @JsModule
annotation instead.
url
- the URL to load the JavaScript module from, not
null
loadMode
- this argument is ignored and the loadMode
will
always be LoadMode.EAGER
since LoadMode
doesn't work with Dependency.Type.JS_MODULE
. See Deprecated
section for more details.public void addHtmlImport(String url)
UnsupportedOperationException
.
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
Is is guaranteed that html import will be loaded before the first page
load. For more options, refer to addHtmlImport(String, LoadMode)
url
- the URL to load the HTML import from, not null
UnsupportedOperationException
- if called outside of compatibility mode.public void addHtmlImport(String url, LoadMode loadMode)
UnsupportedOperationException
.
Relative URLs are interpreted as relative to the configured
frontend
directory location. You can prefix the URL with
context://
to make it relative to the context path or use an
absolute URL to refer to files outside the frontend directory.
url
- the URL to load the HTML import from, not null
loadMode
- determines dependency load mode, refer to LoadMode
for
detailsUnsupportedOperationException
- if called outside of compatibility mode.public void addDynamicImport(String expression)
expression
which is
supposed to return a JavaScript Promise
.
No change will be applied on the client side until resulting
Promise
of the expression
is completed. It behaves like
other dependencies (addJavaScript(String)
,
addJsModule(String)
, etc.)
expression
- the JavaScript expression which return a PromiseaddHtmlImport(String)
@Deprecated public Page.ExecutionCanceler executeJavaScript(String expression, Serializable... parameters)
executeJs(String,Serializable...)
instead since
it also allows getting return value back.$0
, $1
, and so on. Supported parameter types
are:
String
Integer
Double
Boolean
JsonValue
Element
(will be sent as null
if the server-side
element instance is not attached when the invocation is sent to the
client)
'prefix' + $0
instead of 'prefix$0'
and
value[$0]
instead of value.$0
since JavaScript
variables aren't evaluated inside strings or property names.expression
- the JavaScript expression to invokeparameters
- parameters to pass to the expressionpublic PendingJavaScriptResult executeJs(String expression, Serializable... parameters)
The returned PendingJavaScriptResult
can be used to retrieve
any return
value from the JavaScript expression. If no
return value handler is registered, the return value will be ignored.
The given parameters will be available to the expression as variables
named $0
, $1
, and so on. Supported parameter
types are:
String
Integer
Double
Boolean
JsonValue
Element
(will be sent as null
if the server-side
element instance is not attached when the invocation is sent to the
client)
'prefix' + $0
instead of 'prefix$0'
and
value[$0]
instead of value.$0
since JavaScript
variables aren't evaluated inside strings or property names.expression
- the JavaScript expression to invokeparameters
- parameters to pass to the expressionpublic History getHistory()
window.history
for this page.public void reload()
public Registration addBrowserWindowResizeListener(BrowserWindowResizeListener resizeListener)
BrowserWindowResizeListener
to this UI. The listener
will be notified whenever the browser window within which this UI resides
is resized.resizeListener
- the listener to add, not null
BrowserWindowResizeListener.browserWindowResized(BrowserWindowResizeEvent)
,
Registration
public void open(String url)
url
- the URL to open.public void open(String url, String windowName)
The supplied windowName
is used as the target name in a
window.open call in the client. This means that special values such as
"_blank", "_self", "_top", "_parent" have special meaning. An empty or
null
window name is also a special case.
"", null and "_self" as windowName
all causes the URL to be
opened in the current window, replacing any old contents. For
downloadable content you should avoid "_self" as "_self" causes the
client to skip rendering of any other changes as it considers them
irrelevant (the page will be replaced by the response from the URL). This
can speed up the opening of a URL, but it might also put the client side
into an inconsistent state if the window content is not completely
replaced e.g., if the URL is downloaded instead of displayed in the
browser.
"_blank" as windowName
causes the URL to always be opened in a
new window or tab (depends on the browser and browser settings).
"_top" and "_parent" as windowName
works as specified by the HTML
standard.
Any other windowName
will open the URL in a window with that
name, either by opening a new window/tab in the browser or by replacing
the contents of an existing window with that name.
url
- the URL to open.windowName
- the name of the window.public void setLocation(String uri)
uri
- the URI to showpublic void setLocation(URI uri)
uri
- the URI to showpublic void retrieveExtendedClientDetails(Page.ExtendedClientDetailsReceiver receiver)
receiver
- the callback to which the details are providedpublic void fetchCurrentURL(SerializableConsumer<URL> callback)
In case you need more control over the execution you can use
executeJs(String, Serializable...)
by passing
return window.location.href
.
NOTE: the URL is not escaped, use URL.toURI()
to escape
it.
callback
- to be notified when the url is resolved.Copyright © 2023. All rights reserved.