protected.java
来自「采用tapestry的简单OA系统」· Java 代码 · 共 43 行
JAVA
43 行
package com.ejsun.entapps.presentation.pages;
import org.apache.tapestry.PageRedirectException;
import org.apache.tapestry.callback.PageCallback;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.event.PageValidateListener;
import com.ejsun.entapps.domain.organization.User;
import com.ejsun.entapps.presentation.Visit;
import com.ejsun.entapps.presentation.pages.user.Login;
import com.ejsun.entapps.util.CurrentUser;
/**
* Base page used for pages that should be protected by the {@link Login} page.
* If the user is not logged in, they are redirected to the Login page first.
* Also, implements an error property and a validationDelegate.
*
* @author Quake Wang (reference Tapestry Vlib example)
* @since 2004-3-21
* @version $Revision: 1.1 $
*
**/
public class Protected extends ApplicationBasePage implements PageValidateListener {
public void pageValidate(PageEvent event) {
Visit visit = (Visit) getVisit();
if (visit != null && visit.isUserLoggedIn()){
CurrentUser.set(visit.getUser());
return;
}
// User not logged in ... redirect through the Login page.
Login login = (Login) getRequestCycle().getPage("Login");
login.setCallback(new PageCallback(this));
throw new PageRedirectException(login);
}
//a quick method to get logined user
public User getUser() {
return ((Visit) getVisit()).getUser();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?