📄 protected.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -