2 Replies Latest reply on Apr 7, 2009 12:12 PM by wilczarz.wilczarz.gmail.com

    pages.xml exception handling not working

    acdias

      Hi,


      I'm starting learning Seam and I'm currently making some tests with the exception handler in the pages.xml, but it's not working.
      I'm using JBoss Tools to generate the project (I think it uses Seam Gen to do it).
      It generates the following pages.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <pages xmlns="http://jboss.com/products/seam/pages"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
             no-conversation-view-id="/home.xhtml"
             login-view-id="/login.xhtml">
          <exception class="org.jboss.seam.framework.EntityNotFoundException">
              <redirect view-id="/error.xhtml">
                  <message severity="warn">Record not found</message>
              </redirect>
          </exception>
          
          <exception class="javax.persistence.EntityNotFoundException">
              <redirect view-id="/error.xhtml">
                  <message severity="warn">Record not found</message>
              </redirect>
          </exception>
          
          <exception class="javax.persistence.EntityExistsException">
              <redirect view-id="/error.xhtml">
                  <message severity="warn">Duplicate record</message>
              </redirect>
          </exception>
          
          <exception class="javax.persistence.OptimisticLockException">
              <end-conversation/>
              <redirect view-id="/error.xhtml">
                  <message severity="warn">Another user changed the same data, please try again</message>
              </redirect>
          </exception>
          
          <exception class="org.jboss.seam.security.AuthorizationException">
              <redirect view-id="/error.xhtml">
                  <message severity="error">You don't have permission to access this resource</message>
              </redirect>
          </exception>
          
          <exception class="org.jboss.seam.security.NotLoggedInException">
              <redirect view-id="/login.xhtml">
                  <message severity="warn">#{messages['org.jboss.seam.NotLoggedIn']}</message>
              </redirect>
          </exception>
          
          <exception class="javax.faces.application.ViewExpiredException">
              <redirect view-id="/error.xhtml">
                  <message severity="warn">Your session has timed out, please try again</message>
              </redirect>
          </exception>
          
          <exception class="org.jboss.seam.ConcurrentRequestTimeoutException" log-level="trace">
            <http-error error-code="503" />
          </exception>
           
          <exception>
              <redirect view-id="/error.xhtml">
                  <message severity="error">Unexpected error, please try again</message>
              </redirect>
          </exception>
          
      </pages>



      I created a sample bean to test the NotLoggedInException



      @Name("testBean")
      @Scope(ScopeType.CONVERSATION)
      @Restrict
      public class TesteController {
      
              String test = "Hello world";
              @Restrict("#{s:hasRole('admin')}")
              public String getTest() {
                      return test;
              }
      
      }



      and the page test.xhtml I only put an h:outputText with the value #{testBean.test}


      When I try to access the page, it doesn't redirect to login.xhtml. It shows the Facelets error page with the stack trace.
      How can I make it redirect to /login.xhtml ?



        • 1. Re: pages.xml exception handling not working
          sherkan777

          For me U try to check



              <exception class="org.jboss.seam.security.NotLoggedInException">
                  <redirect view-id="/login.xhtml">
                      <message severity="warn">#{messages['org.jboss.seam.NotLoggedIn']}</message>
                  </redirect>
              </exception>
          



          to redirect to login page, but in you code u test admin role and rule base security.


          Maybe this should work:



              <exception class="org.jboss.seam.security.AuthorizationException">
                  <redirect view-id="/login.xhtml">
                      <message severity="error">You don't have permission to access this resource</message>
                  </redirect>
              </exception>
          





          • 2. Re: pages.xml exception handling not working
            wilczarz.wilczarz.gmail.com

            If you see Facelets stack trace on errors, you need to disable Facelets development mode in web.xml:


            <context-param>
               <param-name>facelets.DEVELOPMENT</param-name>
               <param-value>false</param-value>
            </context-param>