Uploaded image for project: 'OpenWebBeans'
  1. OpenWebBeans
  2. OWB-1246

CDI Event are not observed across SessionScoped beans

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 1.7.3
    • None
    • Core, Events
    • None

    Description

      I have a simple setup with just one single Session that backs a JSF xhtml file. Within that I fire an event, expeting that both the same session, and any other session will receive the event on submitting.

      However, oddly enough, I can see that during the firing of the event, only the current session receives it, not any other sessions. I am making sure I have two different sessions by using two different browsers (Safari and Firefox in this case).

      See also https://stackoverflow.com/q/51027804/744133

       

      package testevent;
      
      import java.io.Serializable;
      import javax.enterprise.context.SessionScoped;
      import javax.enterprise.event.Event;
      import javax.enterprise.event.Observes;
      import javax.enterprise.event.Reception;
      import javax.inject.Inject;
      import javax.inject.Named;
      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.Logger;
      
      @Named
      @SessionScoped
      public class TestEventSession implements Serializable {
      private String message = "Start Message";
      private String receivedMessage = "";
      
      @Inject
      @ForTest Event<String> messageEvent;
      
      Logger LOG = LogManager.getLogger();
      
      public void messageChanged(@Observes(notifyObserver = Reception.IF_EXISTS) @ForTest String message) {
      LOG.info("messageChanged <-- "+message);
      this.receivedMessage = message;
      }
      
      public String getReceivedMessage() {
      return receivedMessage;
      }
      
      public String getMessage() {
      LOG.info("getMessage --> "+message);
      return message;
      }
      
      public void setMessage(String message) {
      LOG.info("setMessage <-- "+message);
      this.message = message;
      LOG.info("Firing Message Change");
      messageEvent.fire(message);
      LOG.info("Done Firing Message Change");
      }
      }
      
      <?xml version='1.0' encoding='UTF-8' ?> 
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html 
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      >
      <f:view transient="false">
      <h:body>
      <h:form>
      <h:inputText value="#{testEventSession.message}" />
      <h:outputText value="#{testEventSession.receivedMessage}" />
      <h:commandButton value="Submit"/>
      <h:button value="Refresh" />
      </h:form>
      </h:body>
      </f:view>
      </html>
      
       
      package testevent; 
      import static java.lang.annotation.ElementType.FIELD; 
      import static java.lang.annotation.ElementType.METHOD; 
      import static java.lang.annotation.ElementType.PARAMETER; 
      import static java.lang.annotation.ElementType.TYPE; 
      import static java.lang.annotation.RetentionPolicy.RUNTIME; 
      import java.lang.annotation.Retention; import java.lang.annotation.Target; 
      import javax.inject.Qualifier; 
      @Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD, PARAMETER, TYPE}) public @interface ForTest { }
      

       

      Attachments

        Activity

          People

            struberg Mark Struberg
            jo_desmet@yahoo.com Jo Desmet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: