Interface IPublicAsyncWebSocketContext

  • All Superinterfaces:
    IPublicPromaInvocationContext, IPublicPromaInvocationContextAsync

    public interface IPublicAsyncWebSocketContext
    extends IPublicPromaInvocationContextAsync
    A specific type of IPublicPromaInvocationContext intended UI handling code within the Java Server Faces framework. It uses web sockets to send HTTP requests via the browser. Instances of this invocation context MUST not be cached or reused, create a new instance when you need a new context.

    Furthermore, this invocation context must be created within an active Faces context, e.g. within a view bean etc. Failure to do so will result in an exception. However, the resulting invocation context can be used to handle the response of a PROMA API call result, even if that response is received within a different thread (as long as the web socket session to the user is still active, which it needs to be or no response would have been received).

    Finally, you can also use the contextualExecutor() to re-enter a Faces context when a PROMA API request completes. This is necessary if you want to access session or view-scoped beans, as the response is usually received on a different, unrelated thread.

    Since:
    8.0.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • contextualExecutor

        de.xima.ximahttp.jakarta_faces.api.IContextualExecutor contextualExecutor()
        Returns an executor that can be used to run an action within a Faces context. Most of the API request handling might take in a separate, non-UI thread. Use this in a bean etc. if you need access to some instance fields or the Faces context in general. Note that the StageChain returned by the IPublicPromaInvocationContextAsync.invoker() already sets the default executor on each produced response stage, so you can simply work with the normal non-async methods.
         IPublicWebSocketInvocationContext pc = ...;
         
         CompletionStage<String> stage = getMessageFromProma(pc);
         
         stage.thenAcceptAsync(message -> {
           // This code is now run within a Faces context, so you can access @ViewScoped beans etc.
         }, pc.facesExecutor());
         

        @implNote The current implementation sends a message via web sockets to the browser, which then initiates a Faces postback request to the server.

        Returns:
        An executor for running within a Faces context. Note that this executor may not be IContextualExecutor.valid().