You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ta...@jakarta.apache.org on 2004/06/08 16:11:25 UTC

[Jakarta Tapestry Wiki] New: FrequentlyAskedQuestions/LogoutLink

   Date: 2004-06-08T07:11:25
   Editor: 216.120.167.2 <>
   Wiki: Jakarta Tapestry Wiki
   Page: FrequentlyAskedQuestions/LogoutLink
   URL: http://wiki.apache.org/jakarta-tapestry/FrequentlyAskedQuestions/LogoutLink

   no comment

New Page:

This is an FAQ on tapestry-users also, so I will base the answer on the response given by Brian Lewis' GMane posting:
[http://article.gmane.org/gmane.comp.java.tapestry.user/8108]

Firstly, you will need to define a listener method in your page class.
----
''For newbies:''
    1. Subclass org.apache.tapestry.html.BasePage
    1. Add listener method public void logout(IRequestCycle cycle) 
    You can use any method name, just keep the signature the same. IRequestCycle is org.apache.tapestry.IRequestCycle
    1. Change page definition (.page) so that your page-specification has class set to your new class. 
----

Inside the listener method, 
{{{
public void logout(IRequestCycle cycle)
{
    IEngine engine = getEngine();
    engine.restart();
}
}}}

If you look at the source for AbstractEngine, you will see that it invalidates the HttpSession and redirects the user to the default URL of the servlet. I personally would put any extra logic required here as it keeps it all in one place.

Thirdly add the listener to your link:
{{{
   <span jwcid="@ActionLink" listener="ognl:listeners.logout">Logout</span>
}}}
----
Another (even simpler) approache is to use a ServiceLink to the RestartService.
{{{
    <span jwcid="@ServiceLink" service="ognl:@org.apache.tapestry.Tapestry@RESTART_SERVICE">Logout</span>
}}}

This will save on the extra class if you don't need it, but stops you from doing other things in your listener without wrapping the Restart Service (like logging a message, giving the user the option to not logout?, etc).


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