Class Page
- java.lang.Object
-
- com.vaadin.server.Page
-
- All Implemented Interfaces:
Serializable
public class Page extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPage.BrowserWindowResizeEventEvent that is fired when a browser window containing a uI is resized.static interfacePage.BrowserWindowResizeListenerListener that gets notified when the size of the browser window containing the uI has changed.static classPage.PopStateEventEvent fired when the URI of aPagechanges (aka HTML 5 popstate event) on the client side due to browsers back/forward functionality.static interfacePage.PopStateListenerListener that that gets notified when the URI of the page changes due to back/forward functionality of the browser.static classPage.StylesContains dynamically injected styles injected in the HTML document at runtime.static classPage.UriFragmentChangedEventEvent fired when the URI fragment of aPagechanges.static interfacePage.UriFragmentChangedListenerDeprecated.UsePage.PopStateListenerinstead
-
Field Summary
Fields Modifier and Type Field Description static BorderStyleBORDER_DEFAULTDeprecated.As of 7.0, useBorderStyle.DEFAULTinstead.static BorderStyleBORDER_MINIMALDeprecated.As of 7.0, useBorderStyle.MINIMALinstead.static BorderStyleBORDER_NONEDeprecated.As of 7.0, useBorderStyle.NONEinstead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RegistrationaddBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)Adds a newPage.BrowserWindowResizeListenerto this UI.voidaddDependency(Dependency dependency)Add a dependency that should be added to the current page.RegistrationaddPopStateListener(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.RegistrationaddUriFragmentChangedListener(Page.UriFragmentChangedListener listener)Deprecated.UseaddPopStateListener(PopStateListener)insteadintgetBrowserWindowHeight()Gets the last known height of the browser window in which this UI resides.intgetBrowserWindowWidth()Gets the last known width of the browser window in which this uI resides.static PagegetCurrent()Gets the Page to which the current uI belongs.JavaScriptgetJavaScript()URIgetLocation()Returns the location URI of this page, as reported by the browser.Collection<Dependency>getPendingDependencies()Returns all pending dependencies.protected PageStategetState(boolean markAsDirty)Returns the page state.Page.StylesgetStyles()Returns that stylesheet associated with this Page.UIgetUI()StringgetUriFragment()Gets the currently set URI fragment.WebBrowsergetWebBrowser()Get access to theWebBrowserthat describes the browser this page is being rendered on.StringgetWindowName()Gets the window.name value of the browser window of this page.voidinit(VaadinRequest request)voidopen(Resource resource, String windowName, boolean tryToOpenAsPopup)Deprecated.As of 7.0, only retained to maintain compatibility with LegacyWindow.open methods.voidopen(Resource resource, String windowName, int width, int height, BorderStyle border)Deprecated.As of 7.0, only retained to maintain compatibility with LegacyWindow.open methods.voidopen(String url, String windowName)Opens the given url in a window with the given name.voidopen(String url, String windowName, boolean tryToOpenAsPopup)Opens the given url in a window with the given name.voidopen(String url, String windowName, int width, int height, BorderStyle border)Opens the given URL in a window with the given size, border and name.voidpaintContent(PaintTarget target)voidpushState(String uri)Updates the browsers URI without causing actual page change.voidpushState(URI uri)Updates the browsers URI without causing actual page change.voidreload()Reloads the page in the browser.voidremoveBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)Deprecated.As of 8.0, replaced byRegistration.remove()in the registration object returned fromaddBrowserWindowResizeListener(BrowserWindowResizeListener).voidremoveUriFragmentChangedListener(Page.UriFragmentChangedListener listener)Deprecated.As of 8.0, replaced byRegistration.remove()in the registration object returned fromaddUriFragmentChangedListener(UriFragmentChangedListener).voidreplaceState(String uri)Updates the browsers URI without causing actual page change in the same way aspushState(String), but does not add new entry to browsers history.voidreplaceState(URI uri)Updates the browsers URI without causing actual page change in the same way aspushState(URI), but does not add new entry to browsers history.voidsetLocation(String uri)Navigates this page to the given URI.voidsetLocation(URI uri)Navigates this page to the given URI.voidsetTitle(String title)Sets the page title.voidsetUriFragment(String newUriFragment)Sets URI fragment.voidsetUriFragment(String newUriFragment, boolean fireEvents)Sets the fragment part in the current location URI.voidshowNotification(Notification notification)Deprecated.As of 7.0, use Notification.show(Page) instead.voidupdateBrowserWindowSize(int width, int height)Deprecated.As of 7.2, useupdateBrowserWindowSize(int, int, boolean)instead.voidupdateBrowserWindowSize(int width, int height, boolean fireEvents)For internal use only.voidupdateLocation(String location)Deprecated.As of 7.2, useupdateLocation(String, boolean, boolean)instead.voidupdateLocation(String location, boolean fireEvents, boolean firePopstate)For internal use only.
-
-
-
Field Detail
-
BORDER_NONE
@Deprecated public static final BorderStyle BORDER_NONE
Deprecated.As of 7.0, useBorderStyle.NONEinstead.
-
BORDER_MINIMAL
@Deprecated public static final BorderStyle BORDER_MINIMAL
Deprecated.As of 7.0, useBorderStyle.MINIMALinstead.
-
BORDER_DEFAULT
@Deprecated public static final BorderStyle BORDER_DEFAULT
Deprecated.As of 7.0, useBorderStyle.DEFAULTinstead.
-
-
Method Detail
-
addUriFragmentChangedListener
@Deprecated public Registration addUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
Deprecated.UseaddPopStateListener(PopStateListener)insteadAdds a listener that gets notified every time the URI fragment of this page is changed. Please note that the initial URI fragment has already been set when a new UI is initialized, so there will not be any initial event for listeners added duringUI.init(VaadinRequest).- Parameters:
listener- the URI fragment listener to add- Returns:
- a registration object for removing the listener
- Since:
- 8.0
- See Also:
getUriFragment(),setUriFragment(String),Registration
-
addPopStateListener
public 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.Note that one only gets notified when the back/forward button affects history changes with-in same UI, created by
pushState(String)orreplaceState(String)functions.- Parameters:
listener- the Popstate listener to add- Returns:
- a registration object for removing the listener
- Since:
- 8.0
- See Also:
getLocation(),Registration
-
removeUriFragmentChangedListener
@Deprecated public void removeUriFragmentChangedListener(Page.UriFragmentChangedListener listener)
Deprecated.As of 8.0, replaced byRegistration.remove()in the registration object returned fromaddUriFragmentChangedListener(UriFragmentChangedListener).Removes a URI fragment listener that was previously added to this page.- Parameters:
listener- the URI fragment listener to remove- See Also:
addUriFragmentChangedListener(UriFragmentChangedListener)
-
setUriFragment
public void setUriFragment(String newUriFragment, boolean fireEvents)
Sets the fragment part in the current location URI. Optionally fires aPage.UriFragmentChangedEvent.The fragment is the optional last component of a URI, prefixed with a hash sign ("#").
Passing an empty string as
newFragmentsets an empty fragment (a trailing "#" in the URI.) Passingnullif 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 ofURI.- Parameters:
newUriFragment- The new fragment.fireEvents- true to fire event- See Also:
getUriFragment(),setLocation(URI),Page.UriFragmentChangedEvent,Page.UriFragmentChangedListener
-
setUriFragment
public void setUriFragment(String newUriFragment)
Sets URI fragment. This method fires aPage.UriFragmentChangedEvent- Parameters:
newUriFragment- id of the new fragment- See Also:
Page.UriFragmentChangedEvent,Page.UriFragmentChangedListener
-
getUriFragment
public String getUriFragment()
Gets the currently set URI fragment.Returns
nullif there is no fragment and an empty string if there is an empty fragment.To listen to changes in fragment, hook a
Page.UriFragmentChangedListener.- Returns:
- the current fragment in browser location URI.
- See Also:
getLocation(),setUriFragment(String),addUriFragmentChangedListener(UriFragmentChangedListener)
-
init
public void init(VaadinRequest request)
-
getWebBrowser
public WebBrowser getWebBrowser()
Get access to theWebBrowserthat describes the browser this page is being rendered on.- Returns:
- a
WebBrowserinstance - Since:
- 7.0
-
getWindowName
public String getWindowName()
Gets the window.name value of the browser window of this page.- Returns:
- the window name,
nullif the name is not known - Since:
- 7.2
-
updateBrowserWindowSize
@Deprecated public void updateBrowserWindowSize(int width, int height)
Deprecated.As of 7.2, useupdateBrowserWindowSize(int, int, boolean)instead.For internal use only. Updates the internal state with the given values. Does not resize the Page or browser window.- Parameters:
width- the new browser window widthheight- the new browse window height
-
updateBrowserWindowSize
public void updateBrowserWindowSize(int width, int height, boolean fireEvents)For internal use only. Updates the internal state with the given values. Does not resize the Page or browser window.- Parameters:
width- the new browser window widthheight- the new browser window heightfireEvents- whether to firePage.BrowserWindowResizeEventif the size changes- Since:
- 7.2
-
addBrowserWindowResizeListener
public Registration addBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Adds a newPage.BrowserWindowResizeListenerto 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).- Parameters:
resizeListener- the listener to add- Returns:
- a registration object for removing the listener
- Since:
- 8.0
- See Also:
Page.BrowserWindowResizeListener.browserWindowResized(BrowserWindowResizeEvent),UI.setResizeLazy(boolean),Registration
-
removeBrowserWindowResizeListener
@Deprecated public void removeBrowserWindowResizeListener(Page.BrowserWindowResizeListener resizeListener)
Deprecated.As of 8.0, replaced byRegistration.remove()in the registration object returned fromaddBrowserWindowResizeListener(BrowserWindowResizeListener).Removes aPage.BrowserWindowResizeListenerfrom this UI. The listener will no longer be notified when the browser window is resized.- Parameters:
resizeListener- the listener to remove
-
getBrowserWindowHeight
public int getBrowserWindowHeight()
Gets the last known height of the browser window in which this UI resides.- Returns:
- the browser window height in pixels
-
getBrowserWindowWidth
public int getBrowserWindowWidth()
Gets the last known width of the browser window in which this uI resides.- Returns:
- the browser window width in pixels
-
getJavaScript
public JavaScript getJavaScript()
-
getStyles
public Page.Styles getStyles()
Returns that stylesheet associated with this Page. The stylesheet contains additional styles injected at runtime into the HTML document.- Since:
- 7.1
-
paintContent
public void paintContent(PaintTarget target) throws PaintException
- Throws:
PaintException
-
setLocation
public void setLocation(String uri)
Navigates this page to the given URI. The contents of this page in the browser is replaced with whatever is returned for the given 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.openmethods orFileDownloaderinstead.- Parameters:
uri- the URI to show- See Also:
open(String, String),FileDownloader
-
setLocation
public void setLocation(URI uri)
Navigates this page to the given URI. The contents of this page in the browser is replaced with whatever is returned for the given 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.openmethods orFileDownloaderinstead.- Parameters:
uri- the URI to show- See Also:
open(String, String),FileDownloader
-
getLocation
public URI getLocation() throws IllegalStateException
Returns the location URI of this page, as reported by the browser. Note that this may not be consistent with the server URI the application is deployed in due to potential proxies, redirections and similar.- Returns:
- The browser location URI.
- Throws:
IllegalStateException- if theDeploymentConfiguration.isSendUrlsAsParameters()is set tofalse
-
pushState
public void pushState(String uri)
Updates the browsers URI without causing actual page change. This method is useful if you wish implement "deep linking" to your application. Calling the method also adds a new entry to clients browser history and you can further usePage.PopStateListenerto track the usage of back/forward feature in browser.Note, the current implementation supports setting only one new uri in one user interaction.
- Parameters:
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.- Since:
- 8.0
-
pushState
public void pushState(URI uri)
Updates the browsers URI without causing actual page change. This method is useful if you wish implement "deep linking" to your application. Calling the method also adds a new entry to clients browser history and you can further usePage.PopStateListenerto track the usage of back/forward feature in browser.Note, the current implementation supports setting only one new uri in one user interaction.
- Parameters:
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.- Since:
- 8.0
-
replaceState
public void replaceState(String uri)
Updates the browsers URI without causing actual page change in the same way aspushState(String), but does not add new entry to browsers history.- Parameters:
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.- Since:
- 8.0
-
replaceState
public void replaceState(URI uri)
Updates the browsers URI without causing actual page change in the same way aspushState(URI), but does not add new entry to browsers history.- Parameters:
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.- Since:
- 8.0
-
updateLocation
@Deprecated public void updateLocation(String location)
Deprecated.As of 7.2, useupdateLocation(String, boolean, boolean)instead.For internal use only. Used to update the server-side location when the client-side location changes.- Parameters:
location- the new location URI
-
updateLocation
public void updateLocation(String location, boolean fireEvents, boolean firePopstate)
For internal use only. Used to update the server-side location when the client-side location changes.- Parameters:
location- the new location URIfireEvents- whether to firePage.UriFragmentChangedEventif the URI fragment changesfirePopstate- whether to firePage.PopStateEvent- Since:
- 8.0
-
open
public void open(String url, String windowName)
Opens the given url in a window with the given name. Equivalent toopen(url, windowName, true) .The supplied
windowNameis 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 ornullwindow name is also a special case."", null and "_self" as
windowNameall 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
windowNamecauses the URL to always be opened in a new window or tab (depends on the browser and browser settings)."_top" and "_parent" as
windowNameworks as specified by the HTML standard.Any other
windowNamewill 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
Linkfor opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.- Parameters:
url- the URL to open.windowName- the name of the window.
-
open
public void open(String url, String windowName, boolean tryToOpenAsPopup)
Opens the given url in a window with the given name. Equivalent toopen(url, windowName, true) .The supplied
windowNameis 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 ornullwindow name is also a special case."", null and "_self" as
windowNameall 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
windowNamecauses the URL to always be opened in a new window or tab (depends on the browser and browser settings)."_top" and "_parent" as
windowNameworks as specified by the HTML standard.Any other
windowNamewill 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
Linkfor opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.- Parameters:
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 window
-
open
public 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. For more information on the meaning ofwindowName, seeopen(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
Linkfor opening the window because browsers are more forgiving when the window is opened directly from a client-side click event.- Parameters:
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.
-
open
@Deprecated public 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 forLegacyWindow.open(Resource, String, int, int, BorderStyle)for discussion about replacing API.
-
open
@Deprecated public void open(Resource resource, String windowName, boolean tryToOpenAsPopup)
Deprecated.As of 7.0, only retained to maintain compatibility with LegacyWindow.open methods. See documentation forLegacyWindow.open(Resource, String, boolean)for discussion about replacing API.
-
showNotification
@Deprecated public void showNotification(Notification notification)
Deprecated.As of 7.0, use Notification.show(Page) instead.Shows a notification message.- Parameters:
notification- The notification message to show- See Also:
Notification
-
getCurrent
public static Page getCurrent()
Gets the Page to which the current uI belongs. This is automatically defined when processing requests to the server. In other cases, (e.g. from background threads), the current uI is not automatically defined.- Returns:
- the current page instance if available, otherwise
null - See Also:
UI.getCurrent()
-
setTitle
public void setTitle(String title)
Sets the page title. The page title is displayed by the browser e.g. as the title of the browser window or as the title of the tab.If this value is set to null, the previously set page title will be left as-is. Set to empty string to clear the title.
- Parameters:
title- the page title to set
-
reload
public void reload()
Reloads the page in the browser.
-
getState
protected PageState getState(boolean markAsDirty)
Returns the page state.The page state is transmitted to UIConnector together with
UIStaterather 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.
- Parameters:
markAsDirty- true to mark the state as dirty- Returns:
- PageState object that can be read in any case and modified if markAsDirty is true
- Since:
- 7.1
-
addDependency
public void addDependency(Dependency dependency)
Add a dependency that should be added to the current page.These dependencies are always added before the dependencies included by using the annotations
HtmlImport,JavaScriptandStyleSheetduring the same request.Please note that these dependencies are always sent to the client side and not filtered out by any
DependencyFilter.- Parameters:
dependency- the dependency to add- Since:
- 8.1
-
getPendingDependencies
public Collection<Dependency> getPendingDependencies()
Returns all pending dependencies.For internal use only, calling this method will clear the pending dependencies.
- Returns:
- the pending dependencies to the current page
- Since:
- 8.1
-
-