Class DesignerPageBean

  • All Implemented Interfaces:
    Serializable

    @Named
    @ViewScoped
    public class DesignerPageBean
    extends Object
    implements Serializable
    Bean for all designer pages. Scopes the designer conversation to the main designer view, initializes the project, keeps track of model changes.
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    See Also:
    Serialized Form
    • Constructor Detail

      • DesignerPageBean

        public DesignerPageBean()
    • Method Detail

      • getContentView

        public EContentView getContentView()
        Returns:
        The content view of the currently opened designer tab.
      • getConversationId

        public String getConversationId()
        Returns:
        The ID of the current designer Conversation.
      • getFormTitle

        public String getFormTitle()
        Returns:
        The current form title. Either from the persisted project, or when the form designer is open, the title as it has been entered in the form designer.
      • handleProjectUpdate

        public void handleProjectUpdate()
        Remote command invoked when the name of the project was updated. Updates the project name in the bottom bar of the designer.
      • handleGenericFileUpload

        public void handleGenericFileUpload​(org.primefaces.event.FileUploadEvent event)
        Handles an uploaded file and posts and forwards to the
        Parameters:
        event - Event with the uploaded data.
      • initChild

        public void initChild()
        Called on page load when a child iframe designer page is loaded. Initializes the designer conversation.
      • initParent

        public void initParent()
        Called on page load when the designer parent page is loaded. Initializes the designer conversation.
      • isChildPage

        public boolean isChildPage()
        Returns:
        Whether the current view scope is a designer child page (iframe) contained in the parent page.
      • isConversationActive

        public boolean isConversationActive()
        Returns:
        Whether the designer conversation is currently active. Normally it should be ended only when the parent view ends.
      • isParentPage

        public boolean isParentPage()
        Returns:
        Whether the current view scope is the designer parent frame that contains the individual iframes.
      • post

        public void post​(ISessionConversationEvent event)
        Posts the given designer conversation event and informs all event handlers that have subscribed to that event. When no designer conversation is active, this is a no-op.
        Parameters:
        event - Event to post.
      • registerEventHandler

        public void registerEventHandler​(ISessionConversationEventHandler eventHandler)
        Registers the given conversation event handler for the active designer conversation. When no designer conversation is active, this is a no-op.
        Parameters:
        eventHandler - Designer conversation event handler to register. All subscriber methods of the event handler will be noticed when the corresponding designer conversation event occurs.
      • registerRequestHandler

        public <T extends Serializable,​R extends ICrossViewScopeRequest<T>> void registerRequestHandler​(Class<R> requestType,
                                                                                                              ICrossViewScopeRequestHandler<T,​R> requestHandler)
        Registers the given conversation request handler for the active designer conversation. When no designer conversation is active, this is a no-op.
        Type Parameters:
        T - Type of the requested data.
        R - Type of the request.
        Parameters:
        requestType - Request type to listen to.
        requestHandler - Designer conversation request handler to register. The handler is called when a request is made.
      • request

        public <T extends Serializable,​R extends ICrossViewScopeRequest<T>> boolean request​(R request,
                                                                                                  Duration timeout,
                                                                                                  ICrossViewScopeResponseConsumer<? super T> handler)
        Allows to (a) invoke the handler within the scope where it was registered, and (b) to retrieve a piece of data from another view scope that participates in the same conversation.

        Assume there are two view scopes A and B. A method running in the scope of A wishes to obtain some data form B. It needs to send a message (such as via an event bus) to B. However, when the message handler of B is invoked synchronously, it will still be within the scope of A and will not have access to the state of B.

        To solve this, A can first store the request data within the shared conversation state. A can send a push message via a web socket to the client (web browser) of B, which can then initiate an AJAX call to the view scope of B. Now B can access the request data from the shared conversation state, create the requested data and store the requested data in the conversation state. Afterwards, B sends a push message to the client (browser) of A, which initiates another AJAX call to the view scope of A. Finally, A can access the response from the conversation state and proceed to process that response.

        Type Parameters:
        T - Type of the requested data.
        R - Type of the request.
        Parameters:
        request - Request to send.
        handler - Handler to invoke when the request completes either successfully or erroneously.
        timeout - Timeout to set on the request. When no response is received within this time frame, the handler is invoked with an error.
        Returns:
        true if there are any pending responses, false if all requests have been processed, such as when no handlers did respond to the request.
      • requestBuilder

        public IRequestHandlerBuilder requestBuilder()
        Returns:
        A new builder for sending multiple requests and performing some logic when all have finished.
      • request

        public <T extends Serializable,​R extends ICrossViewScopeRequest<T>> void request​(R request,
                                                                                               Duration timeout)
        Allows to invoke the handler within the scope where it was registered.

        Assume there are two view scope A and B. A method running in the scope of A wishes to obtain some data form B. It needs to send a message (such as via an event bus) to B. However, when the message handler of B is invoked synchronously, it will still be within the scope of A and will not have access to the state of B.

        To solve this, A can first store the request data within the shared conversation state. A can send a push message via a web socket to the client (web browser) of B, which can then initiate an AJAX call to the view scope of B. Now B can access the request data from the shared conversation state, create the requested data and store the requested data in the conversation state. Afterwards, B sends a push message to the client (browser) of A, which initiates another AJAX call to the view scope of A. Finally, A can access the response from the conversation state and proceed to process that response.

        Type Parameters:
        T - Type of the requested data.
        R - Type of the request.
        Parameters:
        request - Request to send.
        timeout - Timeout to set on the request. When no response is received within this time frame, the handler is invoked with an error.
      • withDesignerConversationModel

        public <R> R withDesignerConversationModel​(Function<DesignerConversationModel,​R> fn)
        The designer conversation model is shared between different views and may thus be accessed in simultaneously by different threads handling different requests. This method acquires a lock to ensure only on thread processed a conversation model at a given time. The lock is held for as long as the given handler fn is invoked. Make sure you do not use the model outside the handler fn.
        Parameters:
        fn - It is given the model for the designer session. This is used to share data between the different views in each iframe. This model is scoped to the designer Conversation.
        Returns:
        The value return by the given handler fn