Class Client
The class representing a client that is connected to the application.
Through this class, certain properties of a connected client can be accessed. Furthermore, connection with the client can be maintained through this class. This is where, for example, messages or JavaScript could be sent between clients. Also, through this class, navigation can be done too.
Certain functions of the class are executed by the class methods. These functions are described (with examples) below.
- Since:
- 4.0
- Author:
- JBStrap
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Shows the specified question message to the user.final <T> T
callJavaScriptFunction
(String block) Calls a JavaScript function, that can have a return value.final <T> T
callJavaScriptFunction
(String functionName, Object... params) Calls a JavaScript function that can have a return valueprotected Client
close()
Closes the specified page.deleteCookie
(String name) Removes a Cookie from the browserfinal void
Shows the specified error message to the userGets the application's baseURLfinal String
Gets the client IDGets the specified Cookie's value.final BasePage
The page that is currently displayedfinal UI
Gets the currently displayed UIfinal CurrentUser
Gets the users who are currently logged inprotected Client.EventQueue
final String
getHost()
Gets the browser hostfinal String
Gets the client's language code, that is set in their browser.final String
Gets the client's platformfinal javax.websocket.Session
Gets the client's WebSocket sessionGets the client session properties in a MapgetSessionProperty
(String name) Gets the specified property (specified by name)getTheme()
Gets the application current themefinal String
Gets the user agentfinal void
Shows an input window to the userboolean
isActive()
The client is active.loadJavaScript
(String... files) Loads the specified JavaScript to the client.final boolean
navigateTo
(String pageId) Closes the current page, and opens the new specified page.final boolean
navigateTo
(String pageId, boolean useCache) Navigates to the specified page.final boolean
navigateTo
(String pageId, Parameters params) Closes the currently displayed page and opens a new page, with the specified parameters.final boolean
navigateTo
(String pageId, Parameters params, boolean useCache) Navigates to the specified page (with the specified parameters).final boolean
final boolean
navigateToForceRefresh
(String pageId) Navigates to the specified page by forcing a refresh of the UI.final boolean
navigateToForceRefresh
(String pageId, Parameters params) Navigates to the specified page (with the specified dynamic parameter(s)) by forcing a refresh of the UI.Places a Cookie in the user's browserfinal void
registerEvents
(Component<?> component) Registers the events of the component (and it's subcomponents) on the clientvoid
reload()
Reloads the user interfacefinal void
runBatch()
final void
runInitScripts
(Component<?> component) Runs the init JavaScript(s) of the component and it's subcomponents on the client.runJavaScript
(String script) Runs the specified JavaScript on the clientfinal void
runJavaScript
(String... javaScripts) Runs the specified JavaScript on the clientfinal void
runJavaScript
(List<String> javaScripts) Runs the specified JavaScript on the clientfinal void
Shows the specified message to the userfinal void
sendBroadcastMessage
(BaseMessage message) sendDebugMessage
(String message) Sends a debug message to the client.sendDebugMessage
(String level, String message) Sends a Debug message to the client, on the specified level.sendErrorMessage
(String message) Sends an Error message to the client.sendInfoMessage
(String message) Sends an Info message to the client.sendLogMessage
(String message) Sends a Log message to the client.sendTraceMessage
(String message) Sends a Trace message to the client.sendWarnMessage
(String message) Sends a Warn message to the client.setApplicationIcon
(String iconFile) Sets the application icon (favicon)setSessionProperty
(String name, Object value) Adds a property to the client session.Set application themeSets the browser title textvoid
showNotification
(NotificationType notificationType, String title) Displays the specified notification on the interface.void
showNotification
(NotificationType notificationType, String title, String message) Displays the specified notification on the interface.void
showNotificationImmediate
(NotificationType notificationType, String title) Displays the specified notification on the interface, immediately, not waiting for other modifying operationsvoid
showNotificationImmediate
(NotificationType notificationType, String title, String message) Displays the specified notification on the interface, immediately, not waiting for other modifying operationsMethods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
-
Constructor Details
-
Client
public Client(javax.websocket.Session session, String baseUrl, String host) throws IllegalAccessException - Parameters:
session
- The instance of the WebSocket sessionbaseUrl
- The base URL of the applicationhost
- The server host name- Throws:
IllegalAccessException
- If the license is not valid, or if the amount of users exceeds the allowed number.
-
-
Method Details
-
sendBroadcastMessage
- Parameters:
message
- The message. Must extend fromBaseMessage
class
-
getClientId
Gets the client ID- Returns:
- The client ID
-
getSession
public final javax.websocket.Session getSession()Gets the client's WebSocket session- Returns:
- The client's WebSocket session
-
getUserAgent
Gets the user agent- Returns:
- The user agent
-
getHost
Gets the browser host- Returns:
- The host
-
getBaseURL
Gets the application's baseURL- Returns:
- The application's baseURL
-
getPlatform
Gets the client's platform- Returns:
- The platform (in String)
-
getLanguageCode
Gets the client's language code, that is set in their browser.- Returns:
- The user's language code
-
getCurrentUI
Gets the currently displayed UI- Returns:
- The instance of the currently displayed UI, or
null
if none are displayed
-
getCurrentPage
The page that is currently displayed- Returns:
- The instance of the currently displayed page. If no page is displayed, returns with
null
-
getCurrentUser
Gets the users who are currently logged in- Returns:
- The CurrentUser object, containing the user's information, or
null
, if no user is signed in.
-
registerEvents
Registers the events of the component (and it's subcomponents) on the client
This method only needs to be used if developing a custom component. When using JBStrap components, the events are registered automatically.
- Parameters:
component
- The component whose events we want to register.- Throws:
NullPointerException
- if the specified component isnull
-
runInitScripts
Runs the init JavaScript(s) of the component and it's subcomponents on the client.
This method only needs to be used if developing a custom component. When using JBStrap components, the components are initialized automatically.
- Parameters:
component
- The component that will be initialized
-
closePage
Closes the specified page.
Only usable if the page cache is used (ie, it is only hidden, but not closed). If we close a page, if the cache isn't used, or has no pages in it, then the user will be navigated to the entry point. This entry point can be set by using the
ENTRY_POINT
JBStrap parameterIf a page is closed, and the page cache is used , and it contains a page other than the closed page, then the user will be navigated to previously (before the closed one) opened page. If the cache's first page is closed, then the user will be navigated to the page that is after it in the cache.
- Parameters:
page
- The page to be closed- Returns:
- The client object
-
setTitle
Sets the browser title text- Parameters:
title
- The title text- Returns:
- The client object
-
setApplicationIcon
Sets the application icon (favicon)- Parameters:
iconFile
- The relative (to the application) URL of the image- Returns:
- The client object
-
runJavaScript
Runs the specified JavaScript on the client- Parameters:
javaScripts
- The JavaScript to be used
-
runJavaScript
Runs the specified JavaScript on the client- Parameters:
javaScripts
- The list of the JavaScript
-
runBatch
public final void runBatch() -
say
Shows the specified message to the user- Parameters:
title
- The message title (header text)message
- The message text
-
error
Shows the specified error message to the user- Parameters:
title
- The error title (header text)message
- The error message
-
showNotification
Displays the specified notification on the interface.- Parameters:
notificationType
- The notification type. See theNotificationType
enum for applicable values.title
- The notification title (header text)- Throws:
NullPointerException
- If the type was specified asnull
-
showNotification
Displays the specified notification on the interface.- Parameters:
notificationType
- The notification type. See theNotificationType
enum for applicable values.title
- The notification title (header text)message
- The message text- Throws:
NullPointerException
- If the type was specified asnull
-
showNotificationImmediate
Displays the specified notification on the interface, immediately, not waiting for other modifying operations- Parameters:
notificationType
- The notification type. See theNotificationType
enum for applicable values.title
- The notification title (header text)- Throws:
NullPointerException
- If the type was specified asnull
-
showNotificationImmediate
public void showNotificationImmediate(NotificationType notificationType, String title, String message) Displays the specified notification on the interface, immediately, not waiting for other modifying operations- Parameters:
notificationType
- The notification type. See theNotificationType
enum for applicable values.title
- The notification title (header text)message
- The message text- Throws:
NullPointerException
- If the type was specified asnull
-
getSessionProperties
Gets the client session properties in a Map- Returns:
- The properties map. The map key is the name, the value is the property value.
-
setSessionProperty
Adds a property to the client session.- Parameters:
name
- The property name. If a property with the same name already exists, it will be overwritten.value
- The property value- Returns:
- The client object
- Throws:
NullPointerException
- If the property name is specified asnull
-
getSessionProperty
Gets the specified property (specified by name)- Parameters:
name
- The property name- Returns:
- The property value, or
null
, if not found - Throws:
NullPointerException
- If the property name was specified asnull
-
reload
public void reload()Reloads the user interface -
getEventQueue
- Returns:
- The Event Queue
-
close
- Returns:
- The client object
-
sendDebugMessage
Sends a debug message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendLogMessage
Sends a Log message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendInfoMessage
Sends an Info message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendErrorMessage
Sends an Error message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendWarnMessage
Sends a Warn message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendTraceMessage
Sends a Trace message to the client. This will appear in the browser console- Parameters:
message
- The message text- Returns:
- The client object
-
sendDebugMessage
Sends a Debug message to the client, on the specified level. This will appear in the browser console- Parameters:
level
- The log level. For the usable levels, see theDebugMessage
class constants.message
- The message text- Returns:
- The client object
-
runJavaScript
Runs the specified JavaScript on the client- Parameters:
script
- The JavaScript. (An anonymous JavaScript block can be used as well.)- Returns:
- The client object
-
callJavaScriptFunction
Calls a JavaScript function, that can have a return value.- Type Parameters:
T
- The type of the return value- Parameters:
block
- The JavaScript block- Returns:
- The JavaScript return value
-
callJavaScriptFunction
Calls a JavaScript function that can have a return value- Type Parameters:
T
- The return value type- Parameters:
functionName
- The function name, or JavaScript block that will be executed Aparams
- The function parameters- Returns:
- The return value
-
loadJavaScript
Loads the specified JavaScript to the client.
If not loaded previously, it will be loaded. If loaded previously, then the specified JavaScript is accessible on the client, so the framework will ignore the load request.
- Parameters:
files
- The URL of the JavaScript- Returns:
- The client object
- Throws:
JavaScriptLoadError
- If there was an error during the loading process
-
ask
Shows the specified question message to the user.- Parameters:
title
- The message title (header text)text
- The message text- Returns:
- Return The user's answer.
true
, if the user clicked the okButton , otherwisefalse
.
-
input
Shows an input window to the user- Parameters:
title
- The message title (header text)text
- The message text- Returns:
- The text that the user typed in. If the user didn't write anything, or closed the window,
by pressing the cancel button, it will return with
null
.
-
init
- Parameters:
hardLinkData
- If the user arrived through a HardLink, the HardLink contentsurlParam
- The URL parameters (to be used with a SoftLink)
-
putCookie
Places a Cookie in the user's browser- Parameters:
name
- The cookie name. If a cookie with the same name exists, it will be overwritten.value
- The cookie valueexpSec
- The cookie expiration, in seconds- Returns:
- The client object
- Throws:
NullPointerException
- If the name was specified asnull
-
deleteCookie
Removes a Cookie from the browser- Parameters:
name
- The cookie name- Returns:
- The client object
-
getCookie
Gets the specified Cookie's value.- Parameters:
name
- The cookie name- Returns:
- The cookie value, or an empty string if the cookie was not found
- Throws:
NullPointerException
- If the name was specified asnull
-
isActive
public boolean isActive()The client is active. The connection between the server and the client is not lost. -
setTheme
Set application theme- Parameters:
theme
- The theme. For a list of available themes, seeThemes
enum- Returns:
- The client object
-
getTheme
Gets the application current theme- Returns:
- The current theme
-