6 Replies Latest reply on Jun 28, 2013 4:46 PM by Horacio Antar

    Problem with errai Event

    Horacio Antar Newbie

      I have a question

      When i use .fire(...) for invoke an event, it is received by the @Observes if it is call in your modulo, but it isn't invoked if it is call from another module(module maven). In pom.xml the dependencies are correct  

       

       

      example 1:

      ******************************************************************************

      module 1 - example SUCCESS

       

      public void saveNewEventHistory(@Observes HumanEventSummary pointHistory) { //my code }

       

       

      -----modulo 1

      @Inject

      private Event pointHistoryEvent;

       

      pointHistoryEvent.fire(new HumanEventSummary(ActionHistoryEnum.TASK_CREATED));

       

      ********************************************************************************

       

      example 2

      ******************************************************************************

      -----module 1 - example NOT INVOKED

       

      public void saveNewEventHistory(@Observes HumanEventSummary pointHistory) { //my code }

       

       

      -----modulo 2

      @Inject

      private Event pointHistoryEvent;

       

      pointHistoryEvent.fire(new HumanEventSummary(ActionHistoryEnum.TASK_CREATED));

       

      ********************************************************************************

       

      Thanks

        • 1. Re: Problem with errai Event
          Christian Sadilek Master

          Hi Horacio,

           

          I'd like to look into this but I need some more information. It looks like your event should be fired and observed on the client (fired in one GWT module and observed by another). Is this correct? Does one of your GWT modules inherit the other? Do both modules have an ErraiApp.properties?

           

          Which module defines your event type (HumanEventSummary)?

           

          Cheers,

          Christian

          • 2. Re: Problem with errai Event
            Horacio Antar Newbie

            Hello Christian

            The application has many modules.

             

            One module(module1 with **Client.gwt.xml) has a  @Observes

            public void saveNewEventHistory(@Observes HumanEventSummary pointHistory) { //my code }

             

            The other modules invoke this @Observes

            @Inject

            private Event pointHistoryEvent;

            pointHistoryEvent.fire(new HumanEventSummary(ActionHistoryEnum.TASK_CREATED));

             

            All the modules have a ErraiApp.properties and this modules have in your pom.xml dependencies of the module1 and this have dependencies with module2.

             

            HumanEventSummary is defined in module2 and this module have your **API.gwt.xml

             

             

            The xmls is inherit from other modules

            <inherits name="**API.gwt.xml"/>

            <inherits name="**Client.gwt.xml"/>

             

            Definition

            @Portable

            public class HumanEventSummary implements Serializable{...}

             

             

            Thanks

            • 3. Re: Problem with errai Event
              Christian Sadilek Master

              Hi Horacio,

               

              I created a quick example which works fine for me (attached as a zip file). It has 3 modules, a module that fires an event, a module that observes an event, and a main module with an EntryPoint that causes the event to get fired in Module1 and observed in Module2.

               

              To test it, you need to mvn clean install Module1 and Module2, then run mvn clean gwt:run on module-main.

               

              Hope that helps tracking down the problem.

               

              Cheers,

              Christian

              • 4. Re: Problem with errai Event
                Horacio Antar Newbie

                Christian, thank you for your time and sorry for my delay in responding.

                 

                The problem was solved but i am worried  by the way I did it.

                In the other modules, it only works if I @Inject the class that have the @Observes, otherwise it does not work.

                My concern is that I am not having decoupling with other modules.

                 

                any suggestions?

                 

                Thanks

                • 5. Re: Problem with errai Event
                  Christian Sadilek Master

                  Hi,

                   

                  Yes, for @Observes to work the bean needs to be managed by Errai's IOC container. Another option you have is to create a bean instance programmatically (instead of having it injected):

                   

                  https://docs.jboss.org/author/display/ERRAI/Client-Side+Bean+Manager

                   

                  This should help you address the coupling issue.

                   

                  Cheers,

                  Christian

                  1 of 1 people found this helpful