3 Replies Latest reply on Mar 19, 2008 3:59 PM by Alessandro Lazarotti

    Exception Handling Problem (2.0.1.GA) - empty view-id

    Rodrigo Yoshima Newbie

      I'm just following the doc. My pages.xml has:



          <exception class="domain.exception.ValidationException">
              <redirect>
                  <message>Ocorreram erros de validação.</message>
              </redirect>
          </exception>
      



      I'm getting this:



      javax.el.ELException: Expression cannot be null
           at org.jboss.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:92)
           at org.jboss.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:151)
           at org.jboss.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:195)
           at org.jboss.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:68)
           at org.jboss.seam.el.SeamExpressionFactory.createValueExpression(SeamExpressionFactory.java:98)
           at org.jboss.seam.core.Expressions$1.createExpression(Expressions.java:106)
           at org.jboss.seam.core.Expressions$1.toUnifiedValueExpression(Expressions.java:98)
           at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:111)
           at org.jboss.seam.exception.ConfigRedirectHandler.getViewId(ConfigRedirectHandler.java:50)
           at org.jboss.seam.exception.RedirectHandler.handle(RedirectHandler.java:33)
           at org.jboss.seam.exception.Exceptions.handle(Exceptions.java:75)



      I see that default pages.xml and pages2.0.xdt changed the view-id attribute definition. I just need that this Exception redirects for the current view. Is it possible?


      Chers...

        • 3. Re: Exception Handling Problem (2.0.1.GA) - empty view-id
          Alessandro Lazarotti Newbie

          Hi Rodrigo !
               
          I use filters for this:


               public void doFilter(ServletRequest request,
                         ServletResponse response,  FilterChain chain) throws IOException, ServletException {
                    
                   if (filterConfig != null){           
                    
                    //declarar um request "final", pq a classe ContextualHttpServletRequest exige que seja final
                   final HttpServletRequest  finalRequest= (HttpServletRequest)request;
                    
                    //classe interna necessária para que um servlet consiga ver qualquer componente Seam  
                   new ContextualHttpServletRequest(finalRequest) { 
          
                          @Override 
                          public void process() throws Exception {
          
                                //PreviousUri é um wrapper simples que encapsula o endereço da requisicao em um componente Seam 
                             PreviousUri previousUri = (PreviousUri) org.jboss.seam.contexts.Contexts.getSessionContext().get("previousUri");
                              if(previousUri==null)previousUri = new PreviousUri();
                              previousUri.setValor(finalRequest.getRequestURI().substring(finalRequest.getContextPath().length()));
                              
                              //setando o componente no contexto Seam, agora é só usa-lo no pages.xml para redirecionamentos
                              org.jboss.seam.contexts.Contexts.getSessionContext().set("previousUri",previousUri);                       
                          } 
                       }.run();     
                       chain.doFilter(request, response);
                   } 
               }



          A simple wrapper component:


          @Name("previousUri")
          public class PreviousUri {
               
               private String valor;
          
               public PreviousUri() {
               }
               
               
          
               public String getValor() {
                    return valor;
               }
          
          
          
               public void setValor(String valor) {
                    this.valor = valor;
               }
          
          
          
               @Override
               public String toString() {
                    return valor;
               }
          }
          


          The pages.xml:


              <exception class="br.com.siq.infrastructure.exception.SiqFtpException">    
                  <redirect view-id="#{previousUri}" >
                      <message severity="ERROR">#{org.jboss.seam.handledException.message}</message>
                  </redirect>
              </exception>