Class BrowserPage

  • All Implemented Interfaces:
    java.io.Serializable


    public abstract class BrowserPage
    extends java.lang.Object
    implements java.io.Serializable
    Since:
    2.0.0
    See Also:
    Serialized Form
    • Field Detail

      • LOGGER

        public static final java.util.logging.Logger LOGGER
    • Constructor Detail

      • BrowserPage

        public BrowserPage​()
    • Method Detail

      • webSocketUrl

        public abstract java.lang.String webSocketUrl​()
      • setWebSocketPushListener

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

        public void addWebSocketPushListener​(java.lang.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 void removeWebSocketPushListener​(java.lang.String sessionId)
        removes the WebSocket listener added for this WebSocket session
        Parameters:
        sessionId - the unique id of WebSocket session
        Since:
        2.1.0
      • websocketMessaged

        @Deprecated
        public 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
      • webSocketMessaged

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

        public abstract AbstractHtml render​()
        Override and use this method to render html content to the client browser page.
        Returns:
        the object of Html class which needs to be displayed in the client browser page.
      • toHtmlString

        public java.lang.String toHtmlString​()
        Returns:
        String equalent to the html string of the tag including the child tags.
      • toHtmlString

        public java.lang.String toHtmlString​(boolean rebuild)
        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

        public java.lang.String toHtmlString​(java.lang.String charset)
        Parameters:
        charset - the charset
        Returns:
        String equalent to the html string of the tag including the child tags.
      • toHtmlString

        public java.lang.String toHtmlString​(boolean rebuild,
                                             java.lang.String charset)
        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.
        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​(java.io.OutputStream os)
                           throws java.io.IOException
        Parameters:
        os - the object of OutputStream to write to.
        Returns:
        the total number of bytes written
        Throws:
        java.io.IOException
        Since:
        2.1.4 void toOutputStream, 2.1.8 int toOutputStream
      • toOutputStream

        public int toOutputStream​(java.io.OutputStream os,
                                  boolean rebuild)
                           throws java.io.IOException
        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:
        java.io.IOException
        Since:
        2.1.4 void toOutputStream, 2.1.8 int toOutputStream
      • toOutputStream

        public int toOutputStream​(java.io.OutputStream os,
                                  java.lang.String charset)
                           throws java.io.IOException
        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:
        java.io.IOException
        Since:
        2.1.4 void toOutputStream, 2.1.8 int toOutputStream
      • toOutputStream

        public int toOutputStream​(java.io.OutputStream os,
                                  boolean rebuild,
                                  java.lang.String charset)
                           throws java.io.IOException
        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:
        java.io.IOException
        Since:
        2.1.4 void toOutputStream, 2.1.8 int toOutputStream
      • getInstanceId

        public java.lang.String getInstanceId​()
        Returns:
        a unique id for this instance
        Since:
        2.0.0
      • isPushQueueEnabled

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

        public 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 void addServerMethod​(java.lang.String methodName,
                                    ServerAsyncMethod serverAsyncMethod)
        Parameters:
        methodName -
        serverAsyncMethod -
        Since:
        2.1.0
      • removeServerMethod

        public void removeServerMethod​(java.lang.String methodName)
        removes the method from
        Parameters:
        methodName -
        Since:
        2.1.0
      • performBrowserPageAction

        public void performBrowserPageAction​(java.nio.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 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 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 boolean isHoldPush​()
        Returns:
        the holdPush true if the push is on hold
        Since:
        2.1.3
      • holdPush

        public 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 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 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 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 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 int getWebSocketHeartbeatInterval​()
        Returns:
        the interval value set by BrowserPage#setWebSocketHeartbeatInterval(int) method.
        Since:
        2.1.8
      • setWebSocketDefultHeartbeatInterval

        public static 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 int getWebSocketDefultHeartbeatInterval​()
        Returns:
        the interval value set by setWebSocketDefultHeartbeatInterval method.
        Since:
        2.1.8
      • setWebSocketDefultReconnectInterval

        public static 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 int getWebSocketDefultReconnectInterval​()
        Returns:
        the interval value set by setWebSocketDefultReconnectInterval method.
        Since:
        2.1.8
      • setWebSocketReconnectInterval

        protected 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 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