9 Replies Latest reply on Mar 19, 2007 12:56 AM by sergeysmirnov

    a4j:poll and jsf lifecyle?

    edbras1

      Hellu,

      A question about the poll tag:
      I have a facelet page with a few pages includes. In one of these page includes I have a a4j:poll that refreshes an output text in the same include.
      I have a region around the output text such that only that part of the page is refreshed, which works correct.

      However, I noticed that even do only that part of the page is refreshed, that all bean properties used by the whole page (including the other includes) are also accessed, just like you request the page for the first time :(..

      I was wandering if this is normal and if this can be improved?.. as it's quite an unncessary overhead I think.

      Please some help and avice.
      Ed

        • 1. Re: a4j:poll and jsf lifecyle?

           

          "edbras1" wrote:

          I have a region around the output text such that only that part of the page is refreshed, which works correct.


          a4j:region is NOT for marking the region for refresh. Most likely you misunderstood how to use it.

          Do you have an action attribute for a4j:poll. If so, it should point to the action method that must return null for ajax response.

          • 2. Re: a4j:poll and jsf lifecyle?
            edbras1

            He Sergey,

            Thanx for your response.

            -- Ok, ... hmmmm.. no I don't have an action attribute in the poll. Should I ?? Does that solve something you think ?

            I have included the plling part below.

            -- Yep, what I understood of the region tag should be used to indicate which part should be encoded/decoded on the server... I don't know all the details... that's true ;)
            Anyway: I first left it out, but then it also updates my other parts on the screen, like the outputtext parts of another form on the screen that are bind to a managed bean property :(..

            If I include the region part, at least I don't have that problem ..

            -- Another problem I seem to have with polling....
            I have a status tag included in some pages that also have the polling page included...
            And at every poll the status tag is run, like the other (not the same as the poll form) form is performing a submit :(....

            I am doing something wrong... but don't seem to get in control of it.. Been trough the examples... but stilll missing something :(...... Hope you can point it out...

            My xhtml part:
            (before I didn't had the region and used a normal h:form just like in the poll example... but ... still problems...
            -----
            <a4j:region>
            <h:outputText escape="false" id="incidentText" value="#{vIncident.incident}" />

            </a4j:region>
            <a4j:form ajaxSingle="true" >
            <a4j:poll id="pollIncident" reRender="incidentText" interval="#{msg['incidentIntervalUpdate']}"/>
            </a4j:form>

            ----

            • 3. Re: a4j:poll and jsf lifecyle?
              edbras1

              Sorry, forgot to disable the html tags (hope this works noww...).
              Anyway: it concerns a marquee tag as you can see ;)

              Here again my xhtml part:
              -----

              <a4j:region>
              <marquee><h:outputText escape="false" id="incidentText" value="#{vIncident.incident}" /></marquee>
              
              </a4j:region>
              <a4j:form ajaxSingle="true" >
              <a4j:poll id="pollIncident" reRender="incidentText" interval="#{msg['incidentIntervalUpdate']}"/>
              </a4j:form>


              • 4. Re: a4j:poll and jsf lifecyle?

                It is really helpful for you to re-read the basic concepts of Ajax4jsf. a4j:region does not make sense in the place and in the case you try to use it. There is no reason for using a4j:form here also.

                The code should be:

                <marquee><h:outputText escape="false" id="incidentText" value="#{vIncident.incident}" /></marquee>
                
                <h:form>
                <a4j:poll id="pollIncident" ajaxSingle="true" reRender="incidentText" interval="#{msg['incidentIntervalUpdate']}"/>
                </h:form>


                About your primary question:
                The component tree is restored on the first phase of JSF lifecycle. So, even it is only a partial update, you can expect that the beans methods will be invoked in order to restore the session.

                • 5. Re: a4j:poll and jsf lifecyle?
                  edbras1

                  He Sergey,

                  Thanks for your answer.
                  Sorry, do my best on the documentation but it's not so easy... :(

                  The above I had as first try ;)..
                  I still have the last problem as mentioned in my previous post, that is:
                  My form on the same page is also submitted and rerendered when a poll event occures. How can I solve that ? (if I type in a value and the polll just occures it restores the input text field with the old stored value)

                  I don't have that problem when I use the region tag.

                  Below is an example of a form.
                  BTW: I have it with all my forms, not only the one below.
                  MY page structure? -> I have ane facelets xhtml page with two includes. One that includes the form below and one that contains the code you posted above.

                  Thanx,
                  Ed

                  ----

                  <h:form id="testIncidentForm" styleClass="formLabel">
                   <h:panelGrid columns="2" styleClass="loginTable">
                   <h:outputLabel for="incidentText" value="Calimiteit" />
                   <h:inputText id="incidentText" value="#{vIncident.incidentNew}" />
                   <a4j:commandLink action="#{vIncident.storeIncident}" value="opvoeren" styleClass="submitConfirm" />
                   <h:outputText value="" />
                   </h:panelGrid>
                   <a4j:status id="statusGeneral">
                   <f:facet name="start">
                   <h:graphicImage value="#{vTemplator.browserUri}images/processing.gif" />
                   </f:facet>
                   </a4j:status>
                  </h:form>


                  • 6. Re: a4j:poll and jsf lifecyle?

                    How it might submitted if you have a separate h:form around the a4j:poll? Do you really have what you post here. Post the whole page.

                    • 7. Re: a4j:poll and jsf lifecyle?
                      edbras1

                      He Sergey,

                      Thanks for your time again.
                      Let me post the main page that is called and his includes.

                      I did that already yesterday but appearantly something went wrong as it isn't here today :(...

                      BTW: I noticed some other strange behavior:
                      I use the sub page navigation through the a4j:include tag. This works good, however I noticed that even if the subpage doesn't call to rerender the h:panelgroup that encloses the a4j:include (like in the examples), the nagivation still works, which I won't expect. (I discovered this as he was rerendering the wrong non-existent control panel due to copy/pase ;) ) So also their I have the idea that "everyting" is "posted" and "refreshed".

                      It smells like some general configuration setting that I set wrong, but have no idea what. I just use the general ajax4jsf and facelets development settings as adviced in the ajax4jsf and facelets manuals.

                      Sorry for all the text, but I hope you can discover something strange.

                      Anyway, here the main page that I call in my browser:
                      --------------

                      <jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                       xmlns:t="http://myfaces.apache.org/tomahawk"
                       xmlns:ui="http://java.sun.com/jsf/facelets">
                      
                       <ui:composition template="#{vTemplator.internalUri}afterLogin.xhtml">
                       <!-- -->
                       <!-- Insert left top menu -->
                       <ui:define name="leftMenuTop">
                       <ui:include src="afterLoginLeftMenuTop.xhtml" />
                       </ui:define>
                       <!-- -->
                       <!-- Insert incident -->
                       <ui:define name="incident">
                       <ui:include src="incident.xhtml" />
                       </ui:define>
                       <!-- -->
                       <!-- Insert main area -->
                       <ui:define name="main">
                       <h:form styleClass="formLabel">
                       <h:panelGrid columns="2" styleClass="loginTable">
                       <h:outputLabel for="incidentText" value="Calimiteit" />
                       <h:inputText id="incidentText" value="#{vIncident.incidentNew}" />
                       <h:panelGroup>
                       <a4j:commandLink action="#{vIncident.storeIncident}"
                       value="opvoeren" styleClass="submitConfirm" />
                       <ui:include src="status.xhtml" />
                       </h:panelGroup>
                       <h:outputText value="" />
                       </h:panelGrid>
                       </h:form>
                       </ui:define>
                       </ui:composition>
                      </jsp:root>
                      

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

                      The first include that is a menu:
                      ------------
                      <jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:t="http://myfaces.apache.org/tomahawk"
                       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                       xmlns:ui="http://java.sun.com/jsf/facelets">
                      
                       <a4j:form>
                       <t:panelNavigation>
                       <t:commandLink action="presentation"
                       value="#{msg['authItemNamePresenation']}"
                       rendered="#{vAuthor.staticsKeys['authItemNamePresenation'] != null and (vAuthen.member.presentation != null) and (vAuthen.member.presentation.text != null)}" />
                      
                       <t:commandLink action="trafficInfo"
                       value="#{msg['trafficInformationMenuText']}"
                       rendered="#{vTrafficInfo.subjects != null and vTrafficInfo.subjects.size > 0}" />
                      
                       <t:commandLink action="newsletter"
                       value="#{msg['authItemNameNewsLetter']}"
                       rendered="#{vAuthor.staticsKeys['authItemNameNewsLetter'] != null}" />
                      
                       <t:commandLink action="userSettings"
                       value="#{msg['authItemNameUserSettings']}"
                       rendered="#{vAuthor.staticsKeys['authItemNameUserSettings'] != null}" />
                      
                       <a href="mailto:#{msg['contactAfterLoginEmail']}">#{msg['contactMenuText']}</a>
                       <br />
                       <t:commandLink action="#{vAuthen.logout}"
                       value="#{msg['logoutMenuText']}"
                       rendered="#{vAuthen.member != null}" />
                      
                       </t:panelNavigation>
                       </a4j:form>
                      </jsp:root>
                      

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

                      And then the incident include that contains the poll:

                      ------
                      <jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:t="http://myfaces.apache.org/tomahawk"
                       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
                       xmlns:ui="http://java.sun.com/jsf/facelets">
                      
                      
                       <marquee>
                       <h:outputText escape="false" id="incidentText"
                       value="#{vIncident.incident}" /></marquee>
                      
                       <h:form>
                       <a4j:poll id="pollIncident" ajaxSingle="true" reRender="incidentText"
                       interval="#{msg['incidentIntervalUpdate']}" />
                       </h:form>
                      </jsp:root>
                      


                      That's it.

                      • 8. Re: a4j:poll and jsf lifecyle?
                        edbras1

                        He Sergey,

                        I hope you still have a moment to have a look at my answer above so maybe we can try to solve this issue.

                        Cheers,
                        Ed

                        • 9. Re: a4j:poll and jsf lifecyle?

                          Putting <a4j:region> around the form with poll is only one guess.