2 Replies Latest reply on Oct 30, 2012 5:58 AM by andreig

    event.rf.data is undefined when pushing with onsubscribed event

    andreig

      Hello,

       

      I try to push some data from the server to the client using onsubscribed event from <a4j:push>. My code looks like this:

       

      <a4j:push address="#{bean.user}@myaddress"

                      onerror="alert(event.rf.data)"

                      ondataavailable="foo(event.rf.data)"

                      onsubscribed="foo(event.rf.data)" />

       

      If I remove onsubscribed event from the push, foo function doesn't get called. With onsubscribed event, foo function is called but event.rf.data is undefined. This happens the first time when the html page is loaded. How could I push the data from the server to the client in this situation?

       

      Thank you!

        • 1. Re: event.rf.data is undefined when pushing with onsubscribed event
          andreig

          After a few more tests I noticed that atmosphere framework is started after the push is done. I've tried to load AtmosphereServlet at the start of the application. I have a login page. Atmosphere framework is started before the login page is rendered. After an user successfuly logs in the atmosphere framework starts again. Is this the normal behaviour?

          • 2. Re: event.rf.data is undefined when pushing with onsubscribed event
            andreig

            I've manage to start Atmosphere framework only once. If you want start it at the application start up you have to add this to your web.xml file under <web-app> tag.

             

            <servlet>

                    <servlet-name>Push Servlet</servlet-name>

                    <servlet-class>org.richfaces.webapp.PushServlet</servlet-class>

                    <load-on-startup>3</load-on-startup>

                    <async-supported>true</async-supported>

                </servlet>

                <servlet-mapping>

                    <servlet-name>Push Servlet</servlet-name>

                    <url-pattern>/__richfaces_push</url-pattern>

                </servlet-mapping>

             

                <!-- setups servlet-mapping in RichFaces configuration -->

                <context-param>

                    <param-name>org.richfaces.push.handlerMapping</param-name>

                    <param-value>/__richfaces_push</param-value>

                </context-param>

             

            My mistake was that I was loading AtmopshereServlet at start up instead of PushServlet. So I was ending having 2 instance of AtmosphereServlet.

             

            Anyway this doesn't solve my initial problem. Looks like "onsubscribe" event can be used only to render components on client. event.rf.data is not yet defined. If you don't want to lose any event.rf.data then you have to make sure that client has subscribed to that address before sending any data.