Class BrowserPage

java.lang.Object
com.webfirmframework.wffweb.server.page.BrowserPage
All Implemented Interfaces:
Serializable

public abstract class BrowserPage extends Object implements Serializable
Since:
2.0.0
See Also:
  • Field Details

  • Constructor Details

    • BrowserPage

      public BrowserPage()
  • Method Details

    • webSocketUrl

      public abstract String webSocketUrl()
    • useExternalDrivePath

      protected String useExternalDrivePath()
      Override and use this method to set path to write temporary files to save heap space.
      Returns:
      the path to store temporary files to save heap space.
      Since:
      3.0.18
    • setWebSocketPushListener

      public final void setWebSocketPushListener(WebSocketPushListener wsListener)
      Parameters:
      wsListener -
      Since:
      2.0.0
    • addWebSocketPushListener

      public final void addWebSocketPushListener(String sessionId, WebSocketPushListener wsListener)
      adds the WebSocket listener for the given WebSocket session
      Parameters:
      sessionId - the unique id of WebSocket session
      wsListener -
      Since:
      2.1.0
    • removeWebSocketPushListener

      public final void removeWebSocketPushListener(String sessionId)
      removes the WebSocket listener added for this WebSocket session
      Parameters:
      sessionId - the unique id of WebSocket session
      Since:
      2.1.0
    • getWsListener

      public final WebSocketPushListener getWsListener()
    • websocketMessaged

      @Deprecated public final void websocketMessaged(byte[] message)
      Deprecated.
      alternative method webSocketMessaged is available for the same job.
      This method will be remove later. Use webSocketMessaged.
      Parameters:
      message - the bytes the received in onmessage
      Since:
      2.0.0
    • onInitialClientPing

      protected void onInitialClientPing(AbstractHtml rootTag)
      It invokes on the first websocket ping, it invokes only once in the whole lifetime of this BrowserPage object. All other client events will be received only after invoking this method. It doesn't have any relation to the websocket heartbeat interval or reconnect interval time so changing such configurations will not have any effect on it. Note: It will not invoke whenever the websocket client reconnects to the server but only once in the whole lifetime.

      Override this method to build the UI instead of BrowserPage#afterRender(AbstractHtml) if you want to build the UI only if the client is able to communication to the server. The BrowserPage#afterRender(AbstractHtml) is invoked before this method (and just after the BrowserPage#render() method) regardless of the client is able to communicate to the server or not.
      Parameters:
      rootTag - the root of the BrowserPage
      Since:
      3.0.18
    • webSocketMessaged

      public final void webSocketMessaged(byte[] message)
      Parameters:
      message - the bytes the received in onmessage
      Since:
      2.1.0
    • beforeRender

      protected void beforeRender()
      Invokes just before render() method. This is an empty method in BrowserPage. Override and use. This method invokes only once per object in all of its life time.
      Since:
      3.0.1
    • render

      public abstract AbstractHtml render()
      Override and use this method to render html content to the client browser page. This method invokes only once per object in all of its life time.
      Returns:
      the object of Html class which needs to be displayed in the client browser page.
    • afterRender

      protected void afterRender(AbstractHtml rootTag)
      Invokes after render() method. This is an empty method in BrowserPage. Override and use. This method invokes only once per object in all of its life time.
      Parameters:
      rootTag - the rootTag returned by render() method.
      Since:
      3.0.1
    • beforeToHtml

      protected void beforeToHtml(AbstractHtml rootTag)
      Invokes before any of the toHtmlString or toOutputStream methods invoked. This is an empty method in BrowserPage. Override and use it. This method will invoke every time before any of the following methods is called, toHtmlString, toOutputStream etc..
      Parameters:
      rootTag - the rootTag returned by render() method.
      Since:
      3.0.1
    • afterToHtml

      protected void afterToHtml(AbstractHtml rootTag)
      Invokes after any of the toHtmlString or toOutputStream methods invoked. This is an empty method in BrowserPage. Override and use it. This method will invoke every time after any of the following methods is called, toHtmlString, toOutputStream etc..
      Parameters:
      rootTag - the rootTag returned by render() method.
      Since:
      3.0.1
    • toHtmlString

      public String toHtmlString()
      NB: this method should not be called under render() method because this method internally calls render() method.
      Returns:
      String equalent to the html string of the tag including the child tags.
    • toHtmlString

      public String toHtmlString(boolean rebuild)
      NB: this method should not be called under render() method because this method internally calls render() method. rebuilds the html string of the tag including the child tags/values if parameter is true, otherwise returns the html string prebuilt and kept in the cache.
      Parameters:
      rebuild - true to rebuild & false to return previously built string.
      Returns:
      String equalent to the html string of the tag including the child tags.
      Since:
      2.1.4
    • toHtmlString

      @Deprecated public String toHtmlString(String charset)
      Deprecated.
      since 3.0.19 as it is unused in the internal implementation
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      charset - the charset
      Returns:
      String equalent to the html string of the tag including the child tags.
    • toHtmlString

      @Deprecated public String toHtmlString(boolean rebuild, String charset)
      Deprecated.
      since 3.0.19 as it is unused in the internal implementation
      NB: this method should not be called under render() method because this method internally calls render() method. rebuilds the html string of the tag including the child tags/values if parameter is true, otherwise returns the html string prebuilt and kept in the cache.
      Parameters:
      rebuild - true to rebuild & false to return previously built string.
      charset - the charset to set for the returning value, eg: StandardCharsets.UTF_8.name()
      Returns:
      String equalent to the html string of the tag including the child tags.
      Since:
      2.1.4
    • toOutputStream

      public int toOutputStream(OutputStream os) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      2.1.4 void toOutputStream, 2.1.8 int toOutputStream
    • toOutputStream

      public int toOutputStream(OutputStream os, boolean rebuild) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      2.1.4 void toOutputStream, 2.1.8 int toOutputStream
    • toOutputStream

      public int toOutputStream(OutputStream os, boolean rebuild, boolean flushOnWrite) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      flushOnWrite - true to flush on each write to OutputStream
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.2
    • toOutputStream

      public int toOutputStream(OutputStream os, String charset) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      charset - the charset
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      2.1.4 void toOutputStream, 2.1.8 int toOutputStream
    • toOutputStream

      public int toOutputStream(OutputStream os, Charset charset, boolean flushOnWrite) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      charset - the charset
      flushOnWrite - true to flush on each write to OutputStream
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.2
    • toOutputStream

      public int toOutputStream(OutputStream os, boolean rebuild, String charset) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      charset - the charset
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      2.1.4 void toOutputStream, 2.1.8 int toOutputStream
    • toOutputStream

      public int toOutputStream(OutputStream os, boolean rebuild, Charset charset, boolean flushOnWrite) throws IOException
      NB: this method should not be called under render() method because this method internally calls render() method.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      charset - the charset
      flushOnWrite - true to flush on each write to OutputStream
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.2
    • toBigHtmlString

      public String toBigHtmlString(boolean rebuild)
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toHtmlString method which is faster than this method. The advantage of toBigHtmlString over toHtmlString is it will never throw StackOverflowError.
      NB:- this method has not been undergone all testing process.
      Parameters:
      rebuild - true to rebuild the tag hierarchy or false to return from cache if available.
      Returns:
      the HTML string similar to toHtmlString method.
      Since:
      3.0.15
    • toBigHtmlString

      public String toBigHtmlString()
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toHtmlString method which is faster than this method. The advantage of toBigHtmlString over toHtmlString is it will never throw StackOverflowError.
      NB:- this method has not been undergone all testing process.
      Returns:
      the HTML string similar to toHtmlString method.
      Since:
      3.0.15
    • toBigOutputStream

      public int toBigOutputStream(OutputStream os, boolean rebuild, Charset charset, boolean flushOnWrite) throws IOException
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toOutputStream method which is faster than this method. The advantage of toBigOutputStream over toOutputStream is it will never throw StackOverflowError and the memory consumed at the time of writing could be available for GC (depends on JVM GC rules).
      NB:- this method has not been undergone all testing process.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      charset - the charset
      flushOnWrite - true to flush on each write to OutputStream
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.15
    • toBigOutputStream

      public int toBigOutputStream(OutputStream os, boolean rebuild, Charset charset) throws IOException
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toOutputStream method which is faster than this method. The advantage of toBigOutputStream over toOutputStream is it will never throw StackOverflowError and the memory consumed at the time of writing could be available for GC (depends on JVM GC rules).
      NB:- this method has not been undergone all testing process.
      Parameters:
      os - the object of OutputStream to write to.
      rebuild - true to rebuild & false to write previously built bytes.
      charset - the charset
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.15
    • toBigOutputStream

      public int toBigOutputStream(OutputStream os, Charset charset) throws IOException
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toOutputStream method which is faster than this method. The advantage of toBigOutputStream over toOutputStream is it will never throw StackOverflowError and the memory consumed at the time of writing could be available for GC (depends on JVM GC rules).
      NB:- this method has not been undergone all testing process.
      Parameters:
      os - the object of OutputStream to write to.
      charset - the charset
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.15
    • toBigOutputStream

      public int toBigOutputStream(OutputStream os, Charset charset, boolean flushOnWrite) throws IOException
      Use this method to produce HTML from very heavy and complicated tag hierarchy. For normal and simple HTML hierarchy use toOutputStream method which is faster than this method. The advantage of toBigOutputStream over toOutputStream is it will never throw StackOverflowError and the memory consumed at the time of writing could be available for GC (depends on JVM GC rules).
      NB:- this method has not been undergone all testing process.
      Parameters:
      os - the object of OutputStream to write to.
      charset - the charset
      flushOnWrite - true to flush on each write to OutputStream
      Returns:
      the total number of bytes written
      Throws:
      IOException
      Since:
      3.0.15
    • getInstanceId

      public final String getInstanceId()
      Returns:
      a unique id for this instance
      Since:
      2.0.0
    • isPushQueueEnabled

      public final boolean isPushQueueEnabled()
      By default, it is set as true.
      Returns:
      the pushQueueEnabled
      Since:
      2.0.2
    • setPushQueueEnabled

      public final void setPushQueueEnabled(boolean enabledPushQueue)
      If the server could not push any server updates it will be put in the queue and when it tries to push in the next time it will first push updates from this queue. By default, it is set as true.
      Parameters:
      enabledPushQueue - the enabledPushQueue to set
      Since:
      2.0.2
    • addServerMethod

      public final void addServerMethod(String methodName, ServerAsyncMethod serverAsyncMethod)
      Parameters:
      methodName -
      serverAsyncMethod -
      Since:
      2.1.0
    • addServerMethod

      public final void addServerMethod(String methodName, ServerAsyncMethod serverAsyncMethod, Object serverSideData)
      Parameters:
      methodName -
      serverAsyncMethod -
      serverSideData - this object will be available in the event of serverAsyncMethod.asyncMethod
      Since:
      3.0.2
    • removeServerMethod

      public final void removeServerMethod(String methodName)
      removes the method from
      Parameters:
      methodName -
      Since:
      2.1.0
    • performBrowserPageAction

      public final void performBrowserPageAction(ByteBuffer actionByteBuffer)
      performs action provided by BrowserPageAction.
      Parameters:
      actionByteBuffer - The ByteBuffer object taken from BrowserPageAction .Eg:- BrowserPageAction.RELOAD.getActionByteBuffer();
      Since:
      2.1.0
    • isPushQueueOnNewWebSocketListener

      public final boolean isPushQueueOnNewWebSocketListener()
      Returns:
      the pushQueueOnNewWebSocketListener true if it's enabled otherwise false. By default it's set as true.
      Since:
      2.1.1
    • setPushQueueOnNewWebSocketListener

      public final void setPushQueueOnNewWebSocketListener(boolean pushQueueOnNewWebSocketListener)
      By default it's set as true. If it's enabled then the wffbmBytesQueue will be pushed when new webSocket listener is added/set.
      Parameters:
      pushQueueOnNewWebSocketListener - the pushQueueOnNewWebSocketListener to set. Pass true to enable this option and false to disable this option.
      Since:
      2.1.1
    • isHoldPush

      public final boolean isHoldPush()
      Returns:
      the holdPush true if the push is on hold
      Since:
      2.1.3
    • holdPush

      public final void holdPush()
      holds push if not already on hold until unholdPush is called Usage :-
       try {
           browserPage.holdPush();
      
           for (AbstractHtml tag : tags) {
               tag.removeAttributes("style");
           }
           // other tag manipulations
       } finally {
           browserPage.unholdPush();
       }
       
      Since:
      2.1.3
    • unholdPush

      public final void unholdPush()
      unholds push if not already unheld. Usage :-
       try {
           browserPage.holdPush();
      
           for (AbstractHtml tag : tags) {
               tag.removeAttributes("style");
           }
           // other tag manipulations
       } finally {
           browserPage.unholdPush();
       }
       
      Since:
      2.1.3
    • getPushQueueSize

      public final int getPushQueueSize()
      Gets the size of internal push queue. This size might not be accurate in multi-threading environment.

      Use case :- Suppose there is a thread in the server which makes real time ui changes. But if the end user lost connection and the webSocket is not closed connection, in such case the developer can decide whether to make any more ui updates from server when the pushQueueSize exceeds a particular limit.

      Returns:
      the size of internal push queue.
      Since:
      2.1.4
    • removeFromContext

      public final void removeFromContext(boolean enable, BrowserPage.On... ons)
      By default On.TAB_CLOSE and On.INIT_REMOVE_PREVIOUS are enabled.
      Parameters:
      enable -
      ons - the instance of On to represent on which browser event the browser page needs to be removed.
      Since:
      2.1.4
    • removedFromContext

      protected void removedFromContext()
      Invokes when this browser page instance is removed from browser page context. Override and use this method to stop long running tasks / threads.
      Since:
      2.1.4
    • contains

      public final boolean contains(AbstractHtml tag) throws NullValueException, NotRenderedException
      To check if the given tag exists in the UI.
      NB:- This method is valid only if browserPage#toHtmlString or browserPage#toOutputStream is called at least once in the life time.
      Parameters:
      tag - the tag object to be checked.
      Returns:
      true if the given tag contains in the BrowserPage i.e. UI. false if the given tag was removed or was not already added in the UI.
      Throws:
      NullValueException - throws this exception if the given tag is null.
      NotRenderedException - if the BrowserPage object is not rendered. i.e. if browserPage#toHtmlString or browserPage#toOutputStream was NOT called at least once in the life time.
      Since:
      2.1.7
    • setWebSocketHeartbeatInterval

      protected final void setWebSocketHeartbeatInterval(int milliseconds)
      Sets the heartbeat ping interval of webSocket client in milliseconds. Give -1 to disable it. By default it's set with -1. It affects only for the corresponding BrowserPage instance from which it is called.
      NB:- This method has effect only if it is called before BrowserPage#render() method return. This method can be called inside BrowserPage#render() method to override the default global heartbeat interval set by BrowserPage#setWebSocketDefultHeartbeatInterval(int) method.
      Parameters:
      milliseconds - the heartbeat ping interval of webSocket client in milliseconds. Give -1 to disable it.
      Since:
      2.1.8
    • getWebSocketHeartbeatInterval

      public final int getWebSocketHeartbeatInterval()
      Returns:
      the interval value set by BrowserPage#setWebSocketHeartbeatInterval(int) method.
      Since:
      2.1.8
    • setWebSocketDefultHeartbeatInterval

      public static final void setWebSocketDefultHeartbeatInterval(int milliseconds)
      Sets the default heartbeat ping interval of webSocket client in milliseconds. Give -1 to disable it. It affects globally. By default it's set with -1 till wffweb-2.1.8 and Since wffweb-2.1.9 it's 25000ms i.e. 25 seconds.
      NB:- This method has effect only if it is called before BrowserPage#render() invocation.
      Parameters:
      milliseconds - the heartbeat ping interval of webSocket client in milliseconds. Give -1 to disable it
      Since:
      2.1.8, 2.1.9 the default value is 25000ms i.e. 25 seconds.
    • getWebSocketDefultHeartbeatInterval

      public static final int getWebSocketDefultHeartbeatInterval()
      Returns:
      the interval value set by setWebSocketDefultHeartbeatInterval method.
      Since:
      2.1.8
    • setWebSocketDefultReconnectInterval

      public static final void setWebSocketDefultReconnectInterval(int milliseconds)
      Sets the default reconnect interval of webSocket client in milliseconds. It affects globally. By default it's set with 2000 ms.
      NB:- This method has effect only if it is called before BrowserPage#render() invocation.
      Parameters:
      milliseconds - the reconnect interval of webSocket client in milliseconds. It must be greater than 0.
      Since:
      2.1.8
    • getWebSocketDefultReconnectInterval

      public static final int getWebSocketDefultReconnectInterval()
      Returns:
      the interval value set by setWebSocketDefultReconnectInterval method.
      Since:
      2.1.8
    • setWebSocketReconnectInterval

      protected final void setWebSocketReconnectInterval(int milliseconds)
      Sets the reconnect interval of webSocket client in milliseconds. Give -1 to disable it. By default it's set with -1. It affects only for the corresponding BrowserPage instance from which it is called.
      NB:- This method has effect only if it is called before BrowserPage#render() method return. This method can be called inside BrowserPage#render() method to override the default global WebSocket reconnect interval set by BrowserPage#setWebSocketDefultReconnectInterval(int) method.
      Parameters:
      milliseconds - the reconnect interval of webSocket client in milliseconds. Give -1 to disable it.
      Since:
      2.1.8
    • getWebSocketReconnectInterval

      public final int getWebSocketReconnectInterval()
      Returns:
      the interval value set by BrowserPage#setWebSocketReconnectInterval(int) method.
      Since:
      2.1.8
    • getTagRepository

      public final TagRepository getTagRepository()
      Gets the TagRepository to do different tag operations. This tag repository is specific to this BrowserPage instance.
      Returns:
      the TagRepository object to do different tag operations. Or null if any one of the BrowserPage#toString or BrowserPage#toOutputStream methods is not called.
      Since:
      2.1.8
    • setNonceForWffScript

      protected final void setNonceForWffScript(String value)
      Sets nonce attribute value for wff script.
      Parameters:
      value - pass value to set nonce value or pass null to remove nonce attribute
      Since:
      3.0.1
    • getWffScriptSHA256InBase64

      public final String getWffScriptSHA256InBase64()
      Generates and gets the SHA hash of internal wff script as base64 encoded string. NB: this method should not be called under render() method because this method internally calls render() method.
      Returns:
      the wff script (text/javascript) content converted to SHA-256 hash encoded in base64 string.
      Since:
      3.0.1
    • getWffScriptSHA384InBase64

      public final String getWffScriptSHA384InBase64()
      Generates and gets the SHA hash of internal wff script as base64 encoded string. NB: this method should not be called under render() method because this method internally calls render() method.
      Returns:
      the wff script (text/javascript) content converted to SHA-384 hash encoded in base64 string.
      Since:
      3.0.1
    • getWffScriptSHA512InBase64

      public final String getWffScriptSHA512InBase64()
      Generates and gets the SHA hash of internal wff script as base64 encoded string. NB: this method should not be called under render() method because this method internally calls render() method.
      Returns:
      the wff script (text/javascript) content converted to SHA-512 hash encoded in base64 string.
      Since:
      3.0.1
    • setEnableDeferOnWffScript

      protected final void setEnableDeferOnWffScript(boolean enable)
      It must be called from render method to take effect. By default it's set as true. So if Content-Security-Policy is implemented then script-src must allow data:.
      Parameters:
      enable -
      Since:
      3.0.1
    • isEnableDeferOnWffScript

      protected final boolean isEnableDeferOnWffScript()
      by default it's true.
      Returns:
      true if enabled otherwise false
      Since:
      3.0.1
    • isAutoremoveWffScript

      protected final boolean isAutoremoveWffScript()
      By default it is true.
      Returns:
      the current state
      Since:
      3.0.1
    • setAutoremoveWffScript

      protected final void setAutoremoveWffScript(boolean autoremoveWffScript)
      Automatically removes the wff script tag after loading it from the ui. By default it is true.
      Parameters:
      autoremoveWffScript -
      Since:
      3.0.1
    • getPayloadProcessor

      @Deprecated public final PayloadProcessor getPayloadProcessor()
      Deprecated.
      this method call may make deadlock somewhere in the application while using multiple threads. Use BrowserPage#newPayloadProcessor().
      Gets the same instance of PayloadProcessor per caller thread for this browser page. This PayloadProcessor can process incoming partial bytes from WebSocket. To manually create new PayloadProcessor use new PayloadProcessor(browserPage).
      Returns:
      new instance of PayloadProcessor/thread
      Since:
      3.0.2
    • removePayloadProcessor

      @Deprecated public final void removePayloadProcessor()
      Deprecated.
      this method call may make deadlock.
      Removes the current instance of PayloadProcessor of this caller thread for this browser page and new instance will be reinitialized when calling getPayloadProcessor() by the same thread.
      Since:
      3.0.2
    • newPayloadProcessor

      public final PayloadProcessor newPayloadProcessor()
      Creates and returns new instance of PayloadProcessor for this browser page. This PayloadProcessor can process incoming partial bytes from WebSocket. To manually create new PayloadProcessor use new PayloadProcessor(browserPage). Use this PayloadProcessor instance only under one thread at a time for its complete payload parts.
      Returns:
      new instance of PayloadProcessor each method call.
      Since:
      3.0.11
    • getExecutor

      protected final Executor getExecutor()
      Returns:
      return the executor object
      Since:
      3.0.15
    • setExecutor

      protected final void setExecutor(Executor executor)
      Sets the executor to run ServerAsyncMethod.asyncMethod(com.webfirmframework.wffweb.wffbm.data.WffBMObject, com.webfirmframework.wffweb.tag.html.attribute.event.ServerAsyncMethod.Event),

      NB: You may need only one copy of executor object for all browserPage instances in the project. Eg:
       
      
       public static final Executor EXECUTOR = Executors.newCachedThreadPool();
       browserPage.setExecutor(EXECUTOR);
       
       

      When Java releases Virtual Thread we may be able to use as follows

       
       public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor();
       browserPage.setExecutor(EXECUTOR);
       
       
      Parameters:
      executor -
      Since:
      3.0.15