public class Page extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Page.BrowserWindowResizeEvent
Event that is fired when a browser window containing a uI is resized.
|
static interface |
Page.BrowserWindowResizeListener
Listener that gets notified when the size of the browser window
containing the uI has changed.
|
static class |
Page.PopStateEvent
Event fired when the URI of a
Page changes (aka HTML 5
popstate event) on the client side due to browsers back/forward
functionality. |
static interface |
Page.PopStateListener
Listener that that gets notified when the URI of the page changes due to
back/forward functionality of the browser.
|
static class |
Page.Styles
Contains dynamically injected styles injected in the HTML document at
runtime.
|
static class |
Page.UriFragmentChangedEvent
Event fired when the URI fragment of a
Page changes. |
static interface |
Page.UriFragmentChangedListener
Deprecated.
Use
Page.PopStateListener instead |
Modifier and Type | Field and Description |
---|---|
static BorderStyle |
BORDER_DEFAULT
Deprecated.
As of 7.0, use
BorderStyle.DEFAULT instead. |
static BorderStyle |
BORDER_MINIMAL
Deprecated.
As of 7.0, use
BorderStyle.MINIMAL instead. |
static BorderStyle |
BORDER_NONE
Deprecated.
As of 7.0, use
BorderStyle.NONE instead. |
Modifier and Type | Method and Description |
---|---|
Registration |
addBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Adds a new
Page.BrowserWindowResizeListener to this UI. |
void |
addDependency(Dependency dependency)
Add a dependency that should be added to the current page.
|
Registration |
addPopStateListener(Page.PopStateListener listener)
Adds a listener that gets notified every time the URI of this page is
changed due to back/forward functionality of the browser.
|
Registration |
addUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
Deprecated.
Use
addPopStateListener(PopStateListener)
instead |
int |
getBrowserWindowHeight()
Gets the last known height of the browser window in which this UI
resides.
|
int |
getBrowserWindowWidth()
Gets the last known width of the browser window in which this uI resides.
|
static Page |
getCurrent()
Gets the Page to which the current uI belongs.
|
JavaScript |
getJavaScript() |
URI |
getLocation()
Returns the location URI of this page, as reported by the browser.
|
Collection<Dependency> |
getPendingDependencies()
Returns all pending dependencies.
|
protected PageState |
getState(boolean markAsDirty)
Returns the page state.
|
Page.Styles |
getStyles()
Returns that stylesheet associated with this Page.
|
UI |
getUI()
|
String |
getUriFragment()
Gets the currently set URI fragment.
|
WebBrowser |
getWebBrowser() |
String |
getWindowName()
Gets the window.name value of the browser window of this page.
|
void |
init(VaadinRequest request) |
void |
open(Resource resource,
String windowName,
boolean tryToOpenAsPopup)
Deprecated.
As of 7.0, only retained to maintain compatibility with
LegacyWindow.open methods. See documentation for
LegacyWindow.open(Resource, String, boolean) for
discussion about replacing API. |
void |
open(Resource resource,
String windowName,
int width,
int height,
BorderStyle border)
Deprecated.
As of 7.0, only retained to maintain compatibility with
LegacyWindow.open methods. See documentation for
LegacyWindow.open(Resource, String, int, int, BorderStyle)
for discussion about replacing API. |
void |
open(String url,
String windowName)
Opens the given url in a window with the given name.
|
void |
open(String url,
String windowName,
boolean tryToOpenAsPopup)
Opens the given url in a window with the given name.
|
void |
open(String url,
String windowName,
int width,
int height,
BorderStyle border)
Opens the given URL in a window with the given size, border and name.
|
void |
paintContent(PaintTarget target) |
void |
pushState(String uri)
Updates the browsers URI without causing actual page change.
|
void |
pushState(URI uri)
Updates the browsers URI without causing actual page change.
|
void |
reload()
Reloads the page in the browser.
|
void |
removeBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Deprecated.
As of 8.0, replaced by
Registration.remove() in the
registration object returned from
addBrowserWindowResizeListener(BrowserWindowResizeListener)
. |
void |
removeUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
Deprecated.
As of 8.0, replaced by
Registration.remove() in the
registration object returned from
addUriFragmentChangedListener(UriFragmentChangedListener) . |
void |
replaceState(String uri)
Updates the browsers URI without causing actual page change in the same
way as
pushState(String) , but does not add new entry to browsers
history. |
void |
replaceState(URI uri)
Updates the browsers URI without causing actual page change in the same
way as
pushState(URI) , but does not add new entry to browsers
history. |
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.
|
void |
setUriFragment(String newUriFragment)
Sets URI fragment.
|
void |
setUriFragment(String newUriFragment,
boolean fireEvents)
Sets the fragment part in the current location URI.
|
void |
showNotification(Notification notification)
Deprecated.
As of 7.0, use Notification.show(Page) instead.
|
void |
updateBrowserWindowSize(int width,
int height)
Deprecated.
As of 7.2, use
updateBrowserWindowSize(int, int, boolean) instead. |
void |
updateBrowserWindowSize(int width,
int height,
boolean fireEvents)
For internal use only.
|
void |
updateLocation(String location)
Deprecated.
As of 7.2, use
#updateLocation(String, boolean)
instead. |
void |
updateLocation(String location,
boolean fireEvents,
boolean firePopstate)
For internal use only.
|
@Deprecated public static final BorderStyle BORDER_NONE
BorderStyle.NONE
instead.@Deprecated public static final BorderStyle BORDER_MINIMAL
BorderStyle.MINIMAL
instead.@Deprecated public static final BorderStyle BORDER_DEFAULT
BorderStyle.DEFAULT
instead.@Deprecated public Registration addUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
addPopStateListener(PopStateListener)
insteadUI.init(VaadinRequest)
.listener
- the URI fragment listener to addgetUriFragment()
,
setUriFragment(String)
,
Registration
public Registration addPopStateListener(Page.PopStateListener listener)
Note that one only gets notified when the back/forward button affects
history changes with-in same UI, created by
pushState(String)
or replaceState(String)
functions.
listener
- the Popstate listener to addgetLocation()
,
Registration
@Deprecated public void removeUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
Registration.remove()
in the
registration object returned from
addUriFragmentChangedListener(UriFragmentChangedListener)
.listener
- the URI fragment listener to removeaddUriFragmentChangedListener(UriFragmentChangedListener)
public void setUriFragment(String newUriFragment, boolean fireEvents)
Page.UriFragmentChangedEvent
.
The fragment is the optional last component of a URI, prefixed with a hash sign ("#").
Passing an empty string as newFragment
sets an empty
fragment (a trailing "#" in the URI.) Passing null
if there
is already a non-null fragment will leave a trailing # in the URI since
removing it would cause the browser to reload the page. This is not fully
consistent with the semantics of URI
.
newUriFragment
- The new fragment.fireEvents
- true to fire eventgetUriFragment()
,
setLocation(URI)
,
Page.UriFragmentChangedEvent
,
Page.UriFragmentChangedListener
public void setUriFragment(String newUriFragment)
Page.UriFragmentChangedEvent
newUriFragment
- id of the new fragmentPage.UriFragmentChangedEvent
,
Page.UriFragmentChangedListener
public String getUriFragment()
Returns null
if there is no fragment and an empty string if
there is an empty fragment.
To listen to changes in fragment, hook a
Page.UriFragmentChangedListener
.
getLocation()
,
setUriFragment(String)
,
addUriFragmentChangedListener(UriFragmentChangedListener)
public void init(VaadinRequest request)
public WebBrowser getWebBrowser()
public String getWindowName()
null
if the name is not known@Deprecated public void updateBrowserWindowSize(int width, int height)
updateBrowserWindowSize(int, int, boolean)
instead.width
- the new browser window widthheight
- the new browse window heightpublic void updateBrowserWindowSize(int width, int height, boolean fireEvents)
width
- the new browser window widthheight
- the new browser window heightfireEvents
- whether to fire Page.BrowserWindowResizeEvent
if the size
changespublic Registration addBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Page.BrowserWindowResizeListener
to this UI. The listener
will be notified whenever the browser window within which this UI resides
is resized.
In most cases, the UI should be in lazy resize mode when using browser
window resize listeners. Otherwise, a large number of events can be
received while a resize is being performed. Use
UI.setResizeLazy(boolean)
.
resizeListener
- the listener to addBrowserWindowResizeListener#browserWindowResized(BrowserWindowResizeEvent)
,
UI.setResizeLazy(boolean)
,
Registration
@Deprecated public void removeBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Registration.remove()
in the
registration object returned from
addBrowserWindowResizeListener(BrowserWindowResizeListener)
.Page.BrowserWindowResizeListener
from this UI. The listener
will no longer be notified when the browser window is resized.resizeListener
- the listener to removepublic int getBrowserWindowHeight()
public int getBrowserWindowWidth()
public JavaScript getJavaScript()
public Page.Styles getStyles()
public void paintContent(PaintTarget target) throws PaintException
PaintException
public void setLocation(String uri)
This method should not be used to start downloads, as the client side
will assume the browser will navigate away when opening the URI. Use one
of the Page.open
methods or FileDownloader
instead.
uri
- the URI to showopen(String, String)
,
FileDownloader
public void setLocation(URI uri)
This method should not be used to start downloads, as the client side
will assume the browser will navigate away when opening the URI. Use one
of the Page.open
methods or FileDownloader
instead.
uri
- the URI to showopen(String, String)
,
FileDownloader
public URI getLocation() throws IllegalStateException
IllegalStateException
- if the
DeploymentConfiguration.isSendUrlsAsParameters()
is
set to false
public void pushState(String uri)
Page.PopStateListener
to track the usage of
back/forward feature in browser.
Note, the current implementation supports setting only one new uri in one user interaction.
uri
- to be used for pushState operation. The URI is resolved over
the current location. If the given URI is absolute, it must be
of same origin as the current URI or the browser will not
accept the new value.public void pushState(URI uri)
Page.PopStateListener
to track the usage of
back/forward feature in browser.
Note, the current implementation supports setting only one new uri in one user interaction.
uri
- the URI to be used for pushState operation. The URI is
resolved over the current location. If the given URI is
absolute, it must be of same origin as the current URI or the
browser will not accept the new value.public void replaceState(String uri)
pushState(String)
, but does not add new entry to browsers
history.uri
- the URI to be used for replaceState operation. The URI is
resolved over the current location. If the given URI is
absolute, it must be of same origin as the current URI or the
browser will not accept the new value.public void replaceState(URI uri)
pushState(URI)
, but does not add new entry to browsers
history.uri
- the URI to be used for replaceState operation. The URI is
resolved over the current location. If the given URI is
absolute, it must be of same origin as the current URI or the
browser will not accept the new value.@Deprecated public void updateLocation(String location)
#updateLocation(String, boolean)
instead.location
- the new location URIpublic void updateLocation(String location, boolean fireEvents, boolean firePopstate)
location
- the new location URIfireEvents
- whether to fire Page.UriFragmentChangedEvent
if the URI
fragment changesfirePopstate
- whether to fire Page.PopStateEvent
public void open(String url, String windowName)
open
(url, windowName, true) .
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.
Please note that opening a popup window in this way may be blocked by the
browser's popup-blocker because the new browser window is opened when
processing a response from the server. To avoid this, you should instead
use Link
for opening the window because browsers are more
forgiving when the window is opened directly from a client-side click
event.
url
- the URL to open.windowName
- the name of the window.public void open(String url, String windowName, boolean tryToOpenAsPopup)
open
(url, windowName, true) .
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.
Please note that opening a popup window in this way may be blocked by the
browser's popup-blocker because the new browser window is opened when
processing a response from the server. To avoid this, you should instead
use Link
for opening the window because browsers are more
forgiving when the window is opened directly from a client-side click
event.
url
- the URL to open.windowName
- the name of the window.tryToOpenAsPopup
- Whether to try to force the resource to be opened in a new
windowpublic void open(String url, String windowName, int width, int height, BorderStyle border)
windowName
, see
open(String, String)
.
Please note that opening a popup window in this way may be blocked by the
browser's popup-blocker because the new browser window is opened when
processing a response from the server. To avoid this, you should instead
use Link
for opening the window because browsers are more
forgiving when the window is opened directly from a client-side click
event.
url
- the URL to open.windowName
- the name of the window.width
- the width of the window in pixelsheight
- the height of the window in pixelsborder
- the border style of the window.@Deprecated public void open(Resource resource, String windowName, int width, int height, BorderStyle border)
LegacyWindow.open(Resource, String, int, int, BorderStyle)
for discussion about replacing API.@Deprecated public void open(Resource resource, String windowName, boolean tryToOpenAsPopup)
LegacyWindow.open(Resource, String, boolean)
for
discussion about replacing API.@Deprecated public void showNotification(Notification notification)
notification
- The notification message to showNotification
public static Page getCurrent()
null
UI.getCurrent()
public void setTitle(String title)
If the title is set to null, it will not left as-is. Set to empty string to clear the title.
title
- the page title to setpublic void reload()
protected PageState getState(boolean markAsDirty)
The page state is transmitted to UIConnector together with
UIState
rather than as an individual entity.
The state should be considered an internal detail of Page. Classes outside of Page should not access it directly but only through public APIs provided by Page.
markAsDirty
- true to mark the state as dirtypublic void addDependency(Dependency dependency)
These dependencies are always added before the dependencies included by
using the annotations HtmlImport
, JavaScript
and
StyleSheet
during the same request.
Please note that these dependencies are always sent to the client side
and not filtered out by any DependencyFilter
.
dependency
- the dependency to addpublic Collection<Dependency> getPendingDependencies()
For internal use only, calling this method will clear the pending dependencies.
Copyright © 2018 Vaadin Ltd. All rights reserved.