1 2 Previous Next 16 Replies Latest reply on Jul 13, 2009 10:00 AM by wesleyhales

    IPC sendEvent from RichFaces (ajax) request

      Hi all,

      I have now a running jsr286 solution with Facelts and RichFaces. I have a <rich:panelMenu> (mode "server"!) with <rich:panelMenuItem> and registered actionListener on each.
      If I click on one panelMenuItem, I can do the following:

      public void portalMenueSelection(ActionEvent actionEvent) {
       String outcome = null;
       FacesContext facesContext = FacesContext.getCurrentInstance();
       ExternalContext externalContext = facesContext.getExternalContext();
       ...
       Object responseObject = externalContext.getResponse();
       if (responseObject != null && responseObject instanceof ActionResponse) {
       ActionResponse actionResponse = (ActionResponse)responseObject;
       MenueSelectionEvent menueSelectionEvent = new MenueSelectionEvent();
       menueSelectionEvent.setAction(action);
       actionResponse.setEvent(MenueSelectionEvent.QNAME, menueSelectionEvent);
       }
      
      facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome);
      }
      


      That works fine and registered Portles receive an event.

      But now, I have an a4j:commandButton that uses ajax. In my corresponding actionListener-method, I tried to cast the responseObject to an ActionResponse, but that doesn't work.

      Now, my question - how could I send an portlet event from an a4j-request (...I know, that the rest of the page will not be rerendered, but I would inform other porlets, anyway)?

      Thanks for advice.
      Carsten

        • 1. Re: IPC sendEvent from RichFaces (ajax) request
          wesleyhales

          Great question. What error do you get when you cast the responseObject?

          • 2. Re: IPC sendEvent from RichFaces (ajax) request

            Hi wesleyhales,

            sorry, I was busy - it took a while...

            I try the following:

            ...myActionEvent-Method...
            
            public void myActionEventMethod(javax.faces.event.ActionEvent event) {
             FacesContext facesContext = FacesContext.getCurrentInstance();
             ExternalContext externalContext = facesContext.getExternalContext();
             Object responseObject = externalContext.getResponse();
             if (responseObject != null && responseObject instanceof ActionResponse) {
             ActionResponse actionResponse = (ActionResponse)responseObject;
             ContextEvent contextEvent = new ContextEvent();
             ...
             actionResponse.setEvent(ContextEvent.QNAME, contextEvent);
             }
            }
            


            I never reach the if-block, because "responseObject" is not an instance of ActionResponse. The debugger says, it's a org.jboss.seam.web.RedirectFilter object... Perhaps that doesn't work with seam, but with pure Richfaces?!

            Best regards,
            Carsten

            • 3. Re: IPC sendEvent from RichFaces (ajax) request
              wesleyhales

              Strange, I just tried it and I get org.jboss.portal.portlet.impl.jsr168.api.ActionResponseImpl@bbacd4 as the object.

              • 4. Re: IPC sendEvent from RichFaces (ajax) request
                ameo

                Hello,

                I have the same problem,

                Use: Faceslets, Richfaces 3.0.0.GA, Portletbridge 1.0.0.6, portal 2.7.1

                a4j :commandButton i fire the method:



                public void fire() {
                 FacesContext facesContext = FacesContext.getCurrentInstance();
                 ExternalContext externalContext = facesContext.getExternalContext();
                 Object responseObject = externalContext.getResponse();
                 if (responseObject != null && responseObject instanceof ActionResponse) {
                 ActionResponse actionResponse = (ActionResponse) responseObject;
                 actionResponse.set...
                 }
                 }
                


                here I geht responseObject of type

                org.ajax4jsf.webapp.FilterServletResponseWrapper


                but no javax.portlet.ActionResponse

                • 5. Re: IPC sendEvent from RichFaces (ajax) request

                  Hi all,
                  Reading this post, I believe you are able to send/receive events outside the scope of the Ajax requests. I am really interested in this, but can't even find a way to do this (how to register the action listener and how to specify that the command button must post an event, and how to redirect to a portal page using a portlet URL in a xhtml file as taglib portlet is not accessible with facelets).
                  Maybe this is obvious to you.

                  Could you please help me ? Any help appreciated, moreover a simple example using richfaces/facelets/portlet + JSR286 events (not ajax way) would be great.

                  Thanks in advance.

                  • 6. Re: IPC sendEvent from RichFaces (ajax) request
                    jeremiepanzer

                    Hi,

                    I have the exact same issue as described in this topic. The object I get from FacesContext.getCurrentInstance().getExternalContext().getResponse() is an instance of org.ajax4jsf.webapp.FilterServletResponseWrapper instead of the expected ActionResponse. Everything is working fine when using a classic h:commandButton.

                    I'm using Jboss Portal 2.7.2, Jboss PortletBridge 1.0.0.B6 and RichFaces 3.3.0GA.

                    One thing I noticed is that the request sent by my browser when clicking the a4j:commandButton contains the GET parameter javax.portlet.faces.DirectLink=true. I have no idea if the issue comes from there, but maybe the ajax request is bypassing the bridge or something and is directly accessing the "standalone" application ?

                    • 7. Re: IPC sendEvent from RichFaces (ajax) request
                      jeremiepanzer

                      After further investigations, I think the Ajax request is sent directly to the web app, bypassing completely the portal and the bridge, hence the object type. Using Firebug, I can see that the request is sent to http://localhost:8080/jsf/index.jsf?javax.portlet.faces.DirectLink=true, which is the location of the standalone application deployed on the server. Did I miss a step in the configuration ?

                      • 8. Re: IPC sendEvent from RichFaces (ajax) request

                         

                        "JeremiePanzer" wrote:
                        Hi,

                        I have the exact same issue as described in this topic. The object I get from FacesContext.getCurrentInstance().getExternalContext().getResponse() is an instance of org.ajax4jsf.webapp.FilterServletResponseWrapper instead of the expected ActionResponse. Everything is working fine when using a classic h:commandButton.


                        I can confirm this using Liferay 5.2.2, JBoss PortletBridge 1.0 CR2 and RichFaces 3.3.1 CR2.

                        It would be nice to get a portletbridge developer statement how portlet events can be sent (and recieved) when the backing bean method was triggered by ajax. This is what the JSF spec says:

                        ExternalContext.getRequest():
                        Return the environment-specific object instance for the current response.
                        
                        Servlet: This is the current request's javax.servlet.http.HttpServletResponse instance.
                        
                        Portlet: This is the current request's javax.portlet.PortletResponse instance, which will be either an ActionResponse or a RenderResponse depending upon when this method is called.



                        "JeremiePanzer" wrote:

                        One thing I noticed is that the request sent by my browser when clicking the a4j:commandButton contains the GET parameter javax.portlet.faces.DirectLink=true. I have no idea if the issue comes from there, but maybe the ajax request is bypassing the bridge or something and is directly accessing the "standalone" application ?


                        Maybe there is a way to toggle this. As said above, some portlet bridge developer statement would be nice on this.

                        • 9. Re: IPC sendEvent from RichFaces (ajax) request
                          wesleyhales

                          This video http://www.vimeo.com/4521877 shows how to check for and operate on the HttpServletRequestWrapper received from an ajax request in the portlet, so just try it with the response.
                          Let me know if you are looking for something else.

                          • 10. Re: IPC sendEvent from RichFaces (ajax) request

                            Hi Wesley,

                            I saw your video JBossPortletBridge Lesson 1 and 2. I found them to be very helpful and thanks a lot for your effort in creating such videos.

                            In connection to this thread (as well as some of my other basic doubts regarding how an AJAX request is served by JSF Portlet bridge) what I now overall understood are -

                            1. The current portlet bridge version does not support making ajax call through the Portlet Container (as using JSR286 specification one can make AJAX call through serveResource method of ResourceServingPortlet). That is the reason why you don't get ActionResponse or ActionRequest objects in ActionEvent

                            2. The typical AJ4 commandButton component of RichFaces sends an AJAX call to a separate FacesServlet (the old way of handling ajax call in JSR 168 world). However, the JSR 301 bridge someway hides the complication.

                            Given this I'm bit surprised why this feature is not there in the JSFPortlet Bridge as making AJAX call right way (so that it easily preserves PortletContext, PortletPreference, Window State, ensures Security etc.) is one of the biggest point made in JSR 286.
                            I went through the latest draft of JSR301 - interestingly even that does not talk anything about resource serving through the bridge. Not sure why this aspect is left outside the JSR 301's scope.

                            However, in your Lesson 2 video you mentioned that in Bridge 2.0 AJAX call would be made much simpler. Does that mean bridge would support AJAX call through resource serving ?

                            Your inputs/explanations are highly appreciated.

                            Regards,
                            Sourav

                            • 11. Re: IPC sendEvent from RichFaces (ajax) request
                              wesleyhales

                               

                              "souravm" wrote:

                              I went through the latest draft of JSR301 - interestingly even that does not talk anything about resource serving through the bridge. Not sure why this aspect is left outside the JSR 301's scope.

                              However, in your Lesson 2 video you mentioned that in Bridge 2.0 AJAX call would be made much simpler. Does that mean bridge would support AJAX call through resource serving ?


                              It's because the current bridge is only covering the 1.0 168 spec. We are working on the 2.0 286 version of the bridge that will cover what you are talking about. The Alpha release of that should be out soon.
                              For now, all you can do are hacks like I mentioned for ajax stuff.


                              • 12. Re: IPC sendEvent from RichFaces (ajax) request

                                Hi Wesley,

                                Thanks for the clarification.

                                This point was not very clear in any of the documentation of RichFaces Portlet bridge (or did I miss it !!!) that it currently supports only jsr 168 based portlet features though it may be used for jsr 286 based portlet also. Especially given the fact that you can run it in JBoss 2.7.x container this confusion is bound to happen unless explained explicitly.

                                However I'm glad that you are coming up with 286 based version pretty soon. I would eagerly wait for the same. And thanks again for the nice effort being put by you guys in building this bridge.

                                Regards,
                                Sourav

                                • 13. Re: IPC sendEvent from RichFaces (ajax) request

                                  Thanks for the clarification. I haven't done IPC over a JSF bridge yet, so please give me some hint on the following topic:

                                  I have two richfaces portlets, one is about sending events and the other is about receiving events.

                                  For the receiver portlet I subclassed GenericFacesPortlet and have implementes/overridden the recieveEvent method:

                                  public class GenericFacesPortletWrapper extends GenericFacesPortlet {
                                  
                                   @Override
                                   public void processEvent(EventRequest request, EventResponse response)
                                   throws PortletException, IOException {
                                   Event event = request.getEvent();
                                   Object value = event.getValue();
                                   }
                                  }
                                  


                                  Receiving events from the sender portlet works this way.

                                  But what I now want to do on the receiver portlet is to set the event's value on a JSF managed bean. However, I don't know how to reach the managed beans from here and how to make the receiver portlet re-render when I changed some managed bean's values. Any help would be appreciated.


                                  Best regards,

                                  Sebastian



                                  • 14. Re: IPC sendEvent from RichFaces (ajax) request

                                    OK I think I've found the solution myself. For anyone interested:

                                    @Override
                                     public void processEvent(EventRequest request, EventResponse response)
                                     throws PortletException, IOException {
                                     Event event = request.getEvent();
                                     Object event.getValue();
                                     PortletSession session = request.getPortletSession(false);
                                     if (session != null) {
                                     MyManagedBean bean = (MyManagedBean ) session.getAttribute("myBean");
                                     bean.setevent(value);
                                    
                                     }
                                     }
                                    


                                    As mentioned by other people here, this only works for non-ajax requests.

                                    1 2 Previous Next