1 Reply Latest reply on Nov 8, 2007 11:11 AM by Pete Muir

    facesMessages and @Redirect question

    John McClain Newbie

      here is my custom exception

      @ApplicationException
      @Redirect(viewId="genericErrorPage.xhtml")
      public class FraudException extends Exception {
       public FraudException(){}
      }
      
      


      here is my genericErrorPage.xhtml
      
      .
      .
      .
      <body>
      <h:messages
       globalOnly="true"
       styleClass="message"
       id="globalMessages" />
      </body>
      
      </html>
      
      



      here is where I throw it:
      
      private void doQry(String qry) throws FraudException {
       Connection con = null;
       Statement st = null;
      
       try {
       con = ds.getConnection();
       st = con.createStatement();
       ResultSet rs = st.executeQuery(qry);
       caseList.clear();
       while (rs.next()) {
       caseList.add(new Tblcase(rs.getObject(1), rs.getObject(2), rs
       .getObject(3), rs.getObject(4), rs.getObject(5), rs
       .getObject(6), rs.getObject(7), rs.getObject(8), rs
       .getObject(9), rs.getObject(10), rs.getObject(11), rs
       .getObject(12)));
       }
       } catch (Exception e) {
       e.printStackTrace();
       log.error("ERROR: " + e.getMessage());
       facesMessages.add("ERROR RENDERING DATA: " + e.getMessage());
       throw new FraudException();
       } finally {
       try {
       con.close();
       st.close();
       } catch (Exception e) {
       e.printStackTrace();
       log.error("ERROR: " + e.getMessage());
       facesMessages.add("ERROR CLOSING CONNECTIONS: " + e.getMessage());
       throw new FraudException();
       }
       }
      
      



      Why Does facesMessages get blown away before rendering in the debug page? The result is no error message displaying.

      When I put a hardcoded message in the redirect, the hardcoded message displays, but the message I programmatically added to facesMessages does not display - as follows:
      @Redirect(viewId="/genericErrorPage.xhtml", message="TESTMESSAGE")
      


      To solve, I tried the following:

      I added this to my session bean
      @Out(Scope = ScopeType.SESSION)
      @In
      facesMessage
      


      That did not work - the errmessage still did not display


      I also tried this:
      @Redirect(viewId="/genericErrorPage.xhtml", message="#{errMessage}")
      

      using an outject errMessage as follows:
      } catch (Exception e) {
       e.printStackTrace();
       log.error("ERROR: " + e.getMessage());
       //facesMessages.add("ERROR RENDERING DATA: " + e.getMessage());
       errMessage = "ERROR RENDERING DATA: " + e.getMessage();
      


      - neither works.