3 Replies Latest reply on Aug 30, 2008 11:12 PM by Michael Courcy

    Displaying error messages on Logout 'Identity.instance().logout()'

    John Skillings Newbie

      Hi all,



      We have a scenario where we would like to display a message after a user logs out. Currently our Logout is handled with 'Identity.instance().logout()'.   After the login authentication, we do some post processing based on certain
      system parameters, prior to rendering the start page.  If the processing is not successful, we want to automatically logout the user, displaying  a logout message - something like Please contact your system admin.


      It appears that adding error messages to the FacesMessages is useless, as  the Identity.instance.logout destroy's the session and any associated messages.


      Appreciate any ideas.


      John


      P.S. Googled and tried all the suggestions out there prior to asking for help.

        • 1. Re: Displaying error messages on Logout 'Identity.instance().logout()'
          Michael Courcy Newbie

          Did you try this ?


                  <page view-id="/logout.xhtml">
               
                   <navigation from-action="#{logoutBean.logout}">
                       <rule if-outcome="systemProblem">
                           <redirect view-id="/logoutWithExplanations.xhtml">
                                <message>#{messages.systemProblem}</message>
                           </redirect>
                       </rule>
                   </navigation>
               
               </page>
          



          I haven't try yet, let me know please.

          • 2. Re: Displaying error messages on Logout 'Identity.instance().logout()'
            Michael Courcy Newbie

            Uh this is not completly relevant


            I meant :


                    <page view-id="/logout.xhtml">
                 
                     <navigation from-action="#{logoutBean.logout}">
                         <rule if-outcome="systemProblem1">
                             <redirect view-id="/logoutWithExplanations.xhtml">
                                  <message>#{messages.systemProblem1}</message>
                             </redirect>
                         </rule>
                            <rule if-outcome="systemProblem2">
                             <redirect view-id="/logoutWithExplanations.xhtml">
                                  <message>#{messages.systemProblem2}</message>
                             </redirect>
                         </rule>
                     </navigation>
                 
                 </page>
            



            Cheers

            • 3. Re: Displaying error messages on Logout 'Identity.instance().logout()'
              Michael Courcy Newbie

              I've been checking using message in a  redirect doesn't work after logout, but using param does work.


              What I did :


              In pages.xml catch method call that could drive to an unexpected logout due to system error:


                   <page view-id="*">
                      ....
                      <!-- catch method call that could potentially drive to a logout -->
                      <navigation from-action="#{logoutBean.logout}">
                           <rule if-outcome="problem1">
                               <redirect view-id="/home.xhtml">
                                    <param name="mess" value="systemProblem1"/>
                               </redirect>
                           </rule>
                           <rule if-outcome="problem2">
                               <redirect view-id="/home.xhtml">
                                    <param name="mess" value="systemProblem2"/>
                               </redirect>
                           </rule>
                       </navigation>
                  </page> 
              



              Dummy implementation of a method that drive to a logout


              @Name("logoutBean")
              public class LogoutBean {
                   
                   @In Identity identity;
                   
                   public String logout(){
                        identity.logout();
                        return "problem1";
                   }
              
              }
              




              Back in pages.xml add method execution in home.xhtml to catch the message in the incoming request.


              <page view-id="/home.xhtml" action="#{messageParameters.addMessage}" />
              




              Helper to retreive the message in the request


              @Name("messageParameters")
              public class MessageParameters {
                   
                   @In FacesMessages facesMessages; 
                   
                   @RequestParameter
                   String mess;
                   
                   public void addMessage(){
                        if(mess!=null)
                             facesMessages.addFromResourceBundle(mess);
                   }
              
              }
              



              But there's a better way as you cannot really recover from your system error is to throw an exception after the logout and then catch the exception with a redirect :


              <exception class="com.mycompany.SystemException1">
                      <redirect view-id="/home.xhtml">
                          <param name="mess" value="systemProblem1"/>
                      </redirect>
              </exception>
              
              <exception class="com.mycompany.SystemException2">
                      <redirect view-id="/home.xhtml">
                          <param name="mess" value="systemProblem2"/>
                      </redirect>
              </exception>