KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pets > ProtectedPage


1 package org.apache.tapestry.pets;
2
3 import org.apache.tapestry.PageRedirectException;
4 import org.apache.tapestry.callback.PageCallback;
5 import org.apache.tapestry.event.PageEvent;
6 import org.apache.tapestry.event.PageValidateListener;
7 import org.apache.tapestry.pets.presentation.pages.SignInPage;
8
9 //Shamelessly taken from the VLib applicattion
10

11 public abstract class ProtectedPage extends PetshopBasePage implements PageValidateListener
12 {
13
14     /**
15      * Checks if the user is logged in. If not, they are sent
16      * to the {@link SignInPage} page before coming back to whatever this
17      * page is.
18      *
19      **/

20
21     public void pageValidate(PageEvent event)
22     {
23         Visit visit = (Visit) getVisit();
24
25         if (visit != null && visit.isUserLoggedIn())
26             return;
27
28         // User not logged in ... redirect through the SignIn page.
29

30         SignInPage signIn = (SignInPage) getRequestCycle().getPage("SignIn");
31
32         signIn.setCallback(new PageCallback(this));
33
34         throw new PageRedirectException(signIn);
35     }
36 }
37
Popular Tags