8 Replies Latest reply on Jun 17, 2009 10:45 AM by Sanjay Bhatt

    How to redirect error page to current view

    David West Newbie
      Hi,

      I've tried the following in my pages.xml:

      <exception class="java.lang.Exception">
         <redirect view-id="#{facesContext.viewRoot.viewId}">
           <message>test</message>
         </redirect>
      </exception>

      I get a null pointer exception because the viewId is null, and a 500 page error.  When I debug seam around the point where the null pointer exception occurs, I see that the EL I have evaluates to null, then it attempts to load the current view ID in code exactly the same way (calling FacesContext.currentInstance().getViewRoot().getViewID()).  Again it evaluates to null and hence the null pointer exception.

      How do I do what I am trying to achieve, displaying errors on the current view with an error message rather than redirecting to some global error page?

      Cheers
        • 3. Re: How to redirect error page to current view
          Pete Muir Master

          Seam 2.0.2 does do FacesContext.currentInstance().getViewRoot().getViewID() (check the code) if you don't specify the view-id - I've seen people report this doesn't work before, so please file an issue in JIRA with a simple seam-gen based example that just shows the problem.


          Thanks

          • 4. Re: How to redirect error page to current view
            David West Newbie
            A work around is to have one of your own beans with the following:

            public String getViewId() {
                      String servletPath = ( (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest() ).getServletPath();
                    return servletPath.substring(0, servletPath.lastIndexOf('.')) + Pages.getSuffix();
                 }

            and use EL that refers to your own method: #{mySeamBean.viewId}.  Looking at the seam code this is what it tries to do if the viewId you supply is null as the facescontext is no longer available.  However this code isn't called because it checks for null rather than an empty string.
            • 6. Re: How to redirect error page to current view
              Sergey Sh Newbie
              Hello, i had the same problem and i resolved it.

              Code below is not working, because facesContext is MockFacesContext and it's viewId property is null.
              `
              <exception class="java.lang.Exception">
                 <redirect view-id="#{facesContext.viewRoot.viewId}">
                   <message>test</message>
                 </redirect>
              </exception>
              `
              Try to use this code
              `
              ...
              <redirect view-id="#{facesContext.externalContext.requestServletPath}">
              ...
              `
              it works fine.
              • 7. Re: How to redirect error page to current view
                Sandeep Shenoy Newbie
                I do it this way
                class SomeHome extends EntityHome<Some>{

                public String persist() {
                  try {
                    some stuff
                   }catch(Exception myException){
                      addFacesMessage();
                      return null;
                   }
                }
                }
                and in page.xml
                <navigation from-action="#{someHome.persist}">
                       <rule>
                            <end-conversation/>
                            <render view-id="/some.xhtml"/>
                        </rule>
                   </navigation>
                key is to return null and then add the <rule> tag in page.xml with render view-id instead of redirect view-id .
                • 8. Re: How to redirect error page to current view
                  Sanjay Bhatt Newbie
                  Hi, I am using SEAM 2.1.0SP1. As per JBSEAM-3190 it is already fixed in 2.1.0 BETA1 and should be available in SEAM 2.1.0SP1.
                  But still am getting the following exception with blank page on the screen while redirecting using  <redirect view-id="#{facesContext.viewRoot.viewId}">

                  javax.faces.el.EvaluationException: uk.co.tntpost.umbrella.exception.UmbApplicationException: marginPercent can not be greater than 1
                       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
                       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
                       at javax.faces.component.UICommand.broadcast(UICommand.java:383)
                       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                       at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
                       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:51)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                       at java.lang.Thread.run(Thread.java:595)
                  Caused by: uk.co.tntpost.umbrella.exception.UmbApplicationException: marginPercent can not be greater than 1
                       at uk.co.tntpost.umbrella.sales.session.facade.impl.QuotationFacadeImpl.calcOtherCostsMarginPercent(QuotationFacadeImpl.java:3169)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                       at sun.reflect.GeneratedMethodAccessor289.invoke(Unknown Source)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
                       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
                       at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:81)
                       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:107)
                       at $Proxy186.calcOtherCostsMarginPercent(Unknown Source)
                       at uk.co.tntpost.umbrella.sales.backing.OtherCostsBacking.setOtherCostDataList(OtherCostsBacking.java:308)
                       at uk.co.tntpost.umbrella.sales.backing.OtherCostsBacking.addNewOtherCost(OtherCostsBacking.java:665)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
                       at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
                       at uk.co.tntpost.umbrella.sales.backing.OtherCostsBacking_$$_javassist_70.addNewOtherCost(OtherCostsBacking_$$_javassist_70.java)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
                       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
                       at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                       at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                       at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
                       ... 51 more


                  I have tried all other options provided above but :(

                  Any help on this would be very much appreciated.