You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Olaf Mertens <pr...@olaf-mertens.com> on 2004/10/19 17:49:32 UTC

clean way to stop request cycle

Hi everybody,

I'm struggling with the following problem:

I have a page property "foo", that is set by a hidden form field. In the 
setFoo()-method a PageRedirectException can occur.

I have to catch the PageRedirectException, because it is not handled correctly 
by Tapestry, but is displayed like an ordinary RuntimeException in the 
Browser.

After I catch the PageRedirectException I do the redirection manually:

///////////////

public void setFoo(String foo) {
 try {
  // do something that can throw 
  // a PageRedirectException

 } catch(PageRedirectException e) {

  String pageName = e.getTargetPageName();

  ILink link =
   getPage().getEngine().getService(Tapestry.PAGE_SERVICE).getLink(
    getPage.getRequestCycle(),
    this,
    new Object[] { pageName });
  try {
   HttpServletResponse res =
    getPage().getRequestCycle().getRequestContext().getResponse();

   res.sendRedirect(link.getAbsoluteURL());

  } catch (IOException e1) {
   throw new ApplicationRuntimeException(e1.getMessage(), e1);
  }
 }
}

///////////////

This manual redirection works, but I get ugly Exceptions in my logfile that 
are caused by the sudden death of the original request cycle.

How can I get rid of the current request cycle in a clean way without breaking 
the tapestry framework?

Many thanks in advance,

Olaf

-- 
--------------------------------------------------
Olaf Mertens

Email: privat@olaf-mertens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Markus Wiederkehr <ma...@gmail.com>.
I had a similar problem once. PageRedirectException is a runtime
exception that is caught by OGNL and wrapped in a checked exception so
it cannot be caught by Tapestry (that is a bug of OGNL in my opinion).

Howard's book pointed me to the solution for my problem. My pages
implement the PageValidateListener interface and the
pageValidate(PageEvent) method. This method should be used to check if
the user may access the page and throw a PageRedirectException if
necessary.

Markus

On Wed, 20 Oct 2004 10:31:00 +0200, Olaf Mertens
<pr...@olaf-mertens.com> wrote:
> Am Dienstag, 19. Oktober 2004 21:31 schrieb Olaf Mertens:
> > > Sorry, the RedirectException isn't handled as well.
> >
> > The problem is, that the PageRedirectException is wrapped in a
> > ognl.MethodFailedException and therefore isn't caught by the method
> > AbstractEngine.service(...)
> 
> I solved my problem by catching the PageRedirectException in the setFoo()
> method, saving it in a variable and rethrowing it during my formSubmit()
> method.
> 
> It seems to me, that you must not throw a PageRedirectException during the
> setting of a property by ognl.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Olaf Mertens <pr...@olaf-mertens.com>.
Am Dienstag, 19. Oktober 2004 21:31 schrieb Olaf Mertens:
> > Sorry, the RedirectException isn't handled as well.
>
> The problem is, that the PageRedirectException is wrapped in a
> ognl.MethodFailedException and therefore isn't caught by the method
> AbstractEngine.service(...)

I solved my problem by catching the PageRedirectException in the setFoo() 
method, saving it in a variable and rethrowing it during my formSubmit() 
method.

It seems to me, that you must not throw a PageRedirectException during the 
setting of a property by ognl.

Olaf

-- 
--------------------------------------------------
Olaf Mertens

Email: privat@olaf-mertens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Olaf Mertens <pr...@olaf-mertens.com>.
Am Dienstag, 19. Oktober 2004 20:25 schrieb Olaf Mertens:
> Sorry, the RedirectException isn't handled as well.

The problem is, that the PageRedirectException is wrapped in a 
ognl.MethodFailedException and therefore isn't caught by the method 
AbstractEngine.service(...)

Olaf
-- 
--------------------------------------------------
Olaf Mertens

Email: privat@olaf-mertens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Mikaël Cluseau <nw...@nwrk.dyndns.org>.
Olaf Mertens wrote:

>Am Dienstag, 19. Oktober 2004 19:43 schrieb Mikaël Cluseau:
>  
>
>>Up to here I'm fine with your code, but after, why don't you just throw
>>a normal RedirectException (they are handled). The code is just one line :
>>
>>throw new RedirectException(link.getURL());
>>    
>>
>
>Sorry, the RedirectException isn't handled as well.
>
If you haven't overidden something of Tapestry (ApplicationServlet) nor 
modified Tapestry and you are using Tapestry-3.0 I really can't help 
you, I use redirect exceptions in lots of places to reload pages after 
actions (and thus have a clean URLs).

Yes, it's a "work for me" :-)

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Olaf Mertens <pr...@olaf-mertens.com>.
Am Dienstag, 19. Oktober 2004 19:43 schrieb Mikaël Cluseau:
> Up to here I'm fine with your code, but after, why don't you just throw
> a normal RedirectException (they are handled). The code is just one line :
>
> throw new RedirectException(link.getURL());

Sorry, the RedirectException isn't handled as well.
Here is the Stacktrace:

[org.apache.tapestry.RedirectException]  at 
ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:796) at 
ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:937)        at 
ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:76)      
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)     
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1629)  at 
ognl.ASTProperty.setValueBody(ASTProperty.java:105)  at 
ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:180)    at 
ognl.SimpleNode.setValue(SimpleNode.java:249)        at 
ognl.Ognl.setValue(Ognl.java:476)    at 
org.apache.tapestry.binding.ExpressionBinding.setObject(ExpressionBinding.java:553)  
at org.apache.tapestry.form.Hidden.renderComponent(Hidden.java:111)     at 
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)     
at 
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624) 
at org.apache.tapestry.form.Form.renderComponent(Form.java:362) at 
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)     
at org.apache.tapestry.form.Form.rewind(Form.java:568)  at 
org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:435)    
at org.apache.tapestry.form.Form.trigger(Form.java:582) at 
org.apache.tapestry.engine.DirectService.service(DirectService.java:169)     
at org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)   
at 
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)        
at org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:326)   
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at 
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:358)       
at 
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)     
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)     
at org.mortbay.http.HttpContext.handle(HttpContext.java:1807)   at 
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525)       
at org.mortbay.http.HttpContext.handle(HttpContext.java:1757)   at 
org.mortbay.http.HttpServer.service(HttpServer.java:879)     at 
org.mortbay.http.HttpConnection.service(HttpConnection.java:790)     at 
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:961)  at 
org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)      at 
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:197)    
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:276)      at 
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:511)

/-- Encapsulated exception ------------\
org.apache.tapestry.RedirectException at 
com.fireos.reconcile_it.web.components.MenuBar.setPageInstance(MenuBar.java:65)      
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:324)     at 
ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:491)  at 
ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:785) at 
ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:937)        at 
ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:76)      
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)     
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1629)  at 
ognl.ASTProperty.setValueBody(ASTProperty.java:105)  at 
ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:180)    at 
ognl.SimpleNode.setValue(SimpleNode.java:249)        at 
ognl.Ognl.setValue(Ognl.java:476)    at 
org.apache.tapestry.binding.ExpressionBinding.setObject(ExpressionBinding.java:553)  
at org.apache.tapestry.form.Hidden.renderComponent(Hidden.java:111)     at 
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)     
at 
org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624) 
at org.apache.tapestry.form.Form.renderComponent(Form.java:362) at 
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)     
at org.apache.tapestry.form.Form.rewind(Form.java:568)  at 
org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:435)    
at org.apache.tapestry.form.Form.trigger(Form.java:582) at 
org.apache.tapestry.engine.DirectService.service(DirectService.java:169)     
at org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)   
at 
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)        
at org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:326)   
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at 
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:358)       
at 
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)     
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)     
at org.mortbay.http.HttpContext.handle(HttpContext.java:1807)   at 
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525)       
at org.mortbay.http.HttpContext.handle(HttpContext.java:1757)   at 
org.mortbay.http.HttpServer.service(HttpServer.java:879)     at 
org.mortbay.http.HttpConnection.service(HttpConnection.java:790)     at 
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:961)  at 
org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)      at 
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:197)    
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:276)      at 
org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:511)


-- 
--------------------------------------------------
Olaf Mertens

Email: privat@olaf-mertens.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: clean way to stop request cycle

Posted by Mikaël Cluseau <nw...@nwrk.dyndns.org>.
Olaf Mertens wrote:

>public void setFoo(String foo) {
> try {
>  // do something that can throw 
>  // a PageRedirectException
>
> } catch(PageRedirectException e) {
>
>  String pageName = e.getTargetPageName();
>
>  ILink link =
>   getPage().getEngine().getService(Tapestry.PAGE_SERVICE).getLink(
>    getPage.getRequestCycle(),
>    this,
>    new Object[] { pageName });
>  
>
Up to here I'm fine with your code, but after, why don't you just throw 
a normal RedirectException (they are handled). The code is just one line :

throw new RedirectException(link.getURL());

>  try {
>   HttpServletResponse res =
>    getPage().getRequestCycle().getRequestContext().getResponse();
>
>   res.sendRedirect(link.getAbsoluteURL());
>
>  } catch (IOException e1) {
>   throw new ApplicationRuntimeException(e1.getMessage(), e1);
>  }
> }
>}
>  
>
Mikael.

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org