6 Replies Latest reply on Jul 1, 2009 3:08 AM by derkd

    Is it possible to ask the framework if the session is expire

    derkd

      Hi all,

      I have an issue with richfaces 3.1.6SR1.
      I have the following code:

      <rich:dataList id="lettercombBeroep" var="_beroep" value="#{lettercombinatieBeroepen}">
      
       <a4j:commandLink id="beroep" action="#{zoekBeroepAction.retrieveBeroepRelatie(_beroep)}" oncomplete="registreer('#{zoekBeroepAction.beroepRelaties.cdBeroepsnaam}+#{zoekBeroepAction.beroepRelaties.omsBeroepsnaam}+#{_beroep.cdBeroepsnaam}+#{_beroep.omsBeroepsnaam}')">#{_beroep.omsBeroepsnaam}</a4j:commandLink>
       <h:outputText id="whiteSpace" value="   "/>
       <a4j:commandLink id="beroepInfoLink" action="#{zoekBeroepAction.retrieveBeroepRelatie(_beroep)}"
       oncomplete="Richfaces.showModalPanel('informationLettercombinatieBeroepPanel');"
       reRender="selectedLettercombinatieBeroep" eventsQueue="beroepLetterQueue" ignoreDupResponses="true">
       <h:graphicImage id="information" style="border-width:0" value="../images/I.png" />
       </a4j:commandLink>
       </rich:dataList>


      when the session is timed the action="#{zoekBeroepAction.retrieveBeroepRelatie(_beroep)}" does not retrieve the information for the oncomplete method.

      I set the
      A4J.AJAX.onExpired = function(loc, expiredMsg){
       alert('Uw sessie is verlopen (Layout)! U wordt teruggeleid naar deze pagina: '+loc);
      
       //return loc;
       window.location = "../timeout.seam";
       }


      in the layout.xhtml and the alert is working but the redirection not because the oncomplete is executed. When removing the oncomplete in the page it works. The oncomplete is an javascript which needs to be executed when the action has retrieved the data. Can I adjust the javascript to ask if the session is expired? or does anybody got a better idea?



        • 1. Re: Is it possible to ask the framework if the session is ex
          nbelaevski

           

          ...alert is working but the redirection not because the oncomplete is executed

          How does oncomplete look like? Why does it stops redirection?

          • 2. Re: Is it possible to ask the framework if the session is ex
            derkd

            Hi Nick,

            Thanks for replying.

            the oncomplete javascript looks like this:

            function registreer(waarde)
            {
            
             tempArray = waarde.split("+");
            
             refCode=tempArray[0];
             refOmschrijving=tempArray[1];
            
             synCode="";
             synOmschrijving="";
            
             if (tempArray.length >= 4)
             {
             synCode=tempArray[2];
             synOmschrijving=tempArray[3];
             }
            
             if(refCode == synCode){
             synCode = "";
             }
             if(refOmschrijving == synOmschrijving){
             synOmschrijving = "";
             }
            
             //alert("waarde=" + waarde + "\n" + refCode + "\n" + refOmschrijving + "\n" + synCode + "\n" + synOmschrijving);
            
             var ClientObj = new Object();
             ClientObj.Code = refCode;
             ClientObj.Omschrijving = refOmschrijving;
             ClientObj.CodeSyn = synCode;
             ClientObj.OmschrijvingSyn = synOmschrijving;
             ClientObj.Type = "Beroep";
             top.pCallBackFunction(ClientObj);
            
             top.window.close();
            
            }
            


            A 3rd party app can open a browser window displaying my web app. My web app passes the id's of some variables back to the 3rd party app.

            the template for the layout of my pages with the richfaces javascript onExpired method looks like this:

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <f:subview contentType="text/html"
             xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:a4j="http://richfaces.org/a4j"
             xmlns:s="http://jboss.com/products/seam/taglib">
            
             <div class="body">
             <a4j:region>
             <script language="javascript">
             A4J.AJAX.onExpired = function(loc, expiredMsg){
             alert('Uw sessie is verlopen (Layout)! U wordt teruggeleid naar deze pagina: '+loc);
            
             //return loc;
             window.location = "../timeout.seam";
             }
             </script>
             </a4j:region>
             <ui:insert name="body"/>
             </div>
            
            
            </f:subview>
            


            • 3. Re: Is it possible to ask the framework if the session is ex
              derkd

              I think I have got it.

              When having the layout.xhtml template file like this:

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
              <f:subview contentType="text/html"
               xmlns="http://www.w3.org/1999/xhtml"
               xmlns:ui="http://java.sun.com/jsf/facelets"
               xmlns:h="http://java.sun.com/jsf/html"
               xmlns:f="http://java.sun.com/jsf/core"
               xmlns:a4j="http://richfaces.org/a4j"
               xmlns:s="http://jboss.com/products/seam/taglib">
              
               <div class="body">
               <a4j:region>
               <script language="javascript">
               A4J.AJAX.onExpired = function(loc, expiredMsg){
               //alert('Uw sessie is verlopen (Layout)! U wordt teruggeleid naar deze pagina: '+loc);
              
               //return loc;
               window.location = "../timeout.seam";
               }
               </script>
               </a4j:region>
               <ui:insert name="body"/>
               </div>
              
              
              </f:subview>


              It will execute the oncomplete, but if I uncomment the alert, the redirect sometimes works... isn't that strange? I assume that retrieving the window.location isn't going fast enough and then the oncomplete is already executing. Howto cancel the oncomplete?

              • 4. Re: Is it possible to ask the framework if the session is ex
                nbelaevski

                Try this:

                A4J.AJAX.onExpired = function(loc, expiredMsg){
                 alert('Uw sessie is verlopen (Layout)! U wordt teruggeleid naar deze pagina: '+loc);
                
                 //return loc;
                 return "../timeout.seam";
                 }


                • 5. Re: Is it possible to ask the framework if the session is ex
                  derkd

                  Unfortunatly it isn't working either. Especially when I remove the alert it goes almost straigt to the oncomplete. So the javascript is going faster than the redirect.

                  I think I have 2 options:
                  solve this in the oncomplete javascript and make a check if the session is expired, but how?

                  or do a check like this:

                  <a4j:commandLink id="beroep" action="#{zoekBeroepAction.retrieveBeroepRelatie(_beroep)}" oncomplete="zoekBeroepAction.beroepRelaties.cdBeroepsnaam != null ? registreer('#{zoekBeroepAction.beroepRelaties.cdBeroepsnaam}+#{zoekBeroepAction.beroepRelaties.omsBeroepsnaam}+#{_beroep.cdBeroepsnaam}+#{_beroep.omsBeroepsnaam}'): 'false' ">#{_beroep.omsBeroepsnaam}</a4j:commandLink>
                  


                  it looks like the last option seem to work!

                  • 6. Re: Is it possible to ask the framework if the session is ex
                    derkd

                    hmmm I made a typo... forgot the #{ and } in oncomplete.

                    So this isn't working either. I now solved it by checking on empty results in the javascript of the oncomplete (the registreer method) and then forward it to another location.

                    If somebody got a better idea, let me know.

                    regards,

                    Derk