5 Replies Latest reply on Jan 27, 2011 2:17 PM by krokodylowy

    How to send event to another page?

    krokodylowy

      Hi

       

      How to send javax.portlet.event to different page?

       

      Two typical solution, like below, can change page but events are consumed on current page

       

      PortalRequestContext prContext = Util.getPortalRequestContext();

      prContext.setResponseComplete(true);

      prContext.getResponse().sendRedirect(prContext.getPortalURI() + destinationPage);

      response.setEvent(event.getActionName(), event);

       

      another one

       

              UIPortal uiPortal = Util.getUIPortal();

              PageNodeEvent<UIPortal> pnevent;

              pnevent = new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, prContext.getPortalURI()

                  + destinationPage);

              UIPageActionListener.ChangePageNodeActionListener cpn = new UIPageActionListener.ChangePageNodeActionListener();

              cpn.execute(pnevent);

      response.setEvent(event.getActionName(), event);

       

       

      What should I do with event's?

        • 1. How to send event to another page?
          rraposa

          What should you do with events? Use them between portlets on the same page! That is how they are meant to work.

           

          What is your use-case? I suspect you can accomplish whatever you're trying to do using a different technique. If your event payload is a String, then a public render parameter might work fine on the page you are redirecting to. Otherwise, you can store the event payload in the APPLICATION_SCOPE of the portlet session and share it amongst portlets on the new page that way.

          • 2. Re: How to send event to another page?
            krokodylowy

            Thanks for response.

            Our portlet use standard events. Sometimes one portlet must send event to another page.

             

            Another portals got some extension's which can be used for this case

            - Liferay and Sun portlet-ext.properties:

                 portlet.container.impl=sun in portal-ext.properties.

                 portlet.event.distribution=ALL_PORTLETS

                 portlet.public.render.parameter.distribution=ALL_PORTLETS

                 portlet.event.max.generation=3

            - Pluto got org/apache/pluto/driver/services/container/EventProviderImpl.java

             

            Workaround should simulate IBM Websphere "cross-page-wire" like a "The IBM documentation says about exporting cross-page-wire: cross-page-wire: represents a property broker wiring between two portlet instances on either the same page or on different pages. A wire connects a source and a target portlet instance so that values which change in the source are propagated to the target"

             

            Pluto got a simply solution. It expose PortalCallbackService.getEventProvider and I can simply add an event

            to queue for next page.

             

            I don't see any similar code in GateIn portal and portlet container (gatein/components/pc) sources.

            • 3. How to send event to another page?
              rraposa

              Hi Krashan,

               

              I see that now - I didn't realize other portals provided an implementation extension for event communication between pages. That capability is not a part of the JSR286 spec.

               

              I do not believe GateIn has this capability.

               

              Rich

              • 4. How to send event to another page?
                krokodylowy

                The best approach should be a some kind of injection after 'cpn.execute' directly to ProcessEventsActionListener but some test do not get a working solution (but portal page is changed)

                 

                        UIPortal uiPortal = Util.getUIPortal();

                        PageNodeEvent<UIPortal> pnevent;

                        pnevent = new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, prContext.getPortalURI()

                            + destinationPage);

                        UIPageActionListener.ChangePageNodeActionListener cpn = new UIPageActionListener.ChangePageNodeActionListener();

                        cpn.execute(pnevent);

                ...

                • 5. Re: How to send event to another page?
                  krokodylowy

                  Partial solution

                   

                  - works good with jsp portlets

                  - page is changed and rendered but requestContext keep's old url (so if needed it can changed only with adding context.redirect(..newPage)

                  at the end

                  - sometimes not work's correctly wih jsf portlet's, page switch break jsf lifecycle so portlet on old page throws NPE (new jsp portlet on

                  new page is displayed correctly)

                   

                  -----------------------------------------

                   

                  PortalRequestContext portalContext = (PortalRequestContext) WebuiRequestContext.getCurrentInstance();

                   

                    // change page

                    UIPortal uiPortal = Util.getUIPortal();

                    PageNodeEvent<UIPortal> pnevent = new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE,  destinationPage);

                    UIPageActionListener.ChangePageNodeActionListener cpn = new UIPageActionListener.ChangePageNodeActionListener();

                    cpn.execute(pnevent);

                   

                    // push event to new page and portlet

                    WebuiRequestContext context = Util.getPortalRequestContext();

                    UIPortalApplication currentPortal = Util.getUIPortalApplication();

                    UIPortal currentSite = currentPortal.getShowedUIPortal();

                    PageNode foundPage = ExoPortalUtils.findPageInNavigations(currentPortal.getNavigations(), destinationPage);

                    if (foundPage == null) {

                      // page not found force standard redirect

                      portalContext.setResponseComplete(true);

                      portalContext.getResponse().sendRedirect(portalContext.getPortalURI()+ destinationPage);

                      return;

                    }

                   

                    // locate ui page

                    UIPage foundUIPage = Util.toUIPage(foundPage, currentSite);

                   

                    // locate ui portlet if defined by name

                    UIPortlet foundUIPortlet = null;

                    if (portlet != null && portlet.length() > 0)

                      foundUIPortlet = ExoPortalUtils.findPortletByName(foundUIPage,portlet);

                   

                    // read current events

                    EventsWrapper eventsWrapper = (EventsWrapper)portalContext.getAttribute(UIPortletActionListener.PORTLET_EVENTS);

                    List<javax.portlet.Event> events = eventsWrapper != null ?eventsWrapper.getEvents() : null;

                    if (events == null)

                      events = new ArrayList<javax.portlet.Event>();

                   

                    // register event for page or portlet

                    javax.portlet.Event portletEvent = new PortletEvent(  new QName(XMLConstants.NULL_NS_URI, event.getActionName()), event);

                    events.add(portletEvent);

                    portalContext.setAttribute(UIPortletActionListener.PORTLET_EVENTS,new EventsWrapper(events));

                   

                    // send event to page or portlet, correct flow may be seen and logged in classes UIPortletActionListener,

                    // PortletApplication, StateAwareResponseImpl i ProcessEventsActionListener u

                    if (foundUIPortlet != null) {

                      foundUIPortlet.createEvent("ProcessEvents",org.exoplatform.webui.event.Event.Phase.PROCESS, portalContext)

                      .broadcast();

                    } else {

                      foundUIPage.createEvent("ProcessEvents",org.exoplatform.webui.event.Event.Phase.PROCESS, portalContext)

                      .broadcast();

                    }

                   

                  // send redirect if requestContext must keep page track

                  // portalContext.getResponse().sendRedirect(portalContext.getPortalURI()+ destinationPage);

                  -----------------------------------------