⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractviewbean.java

📁 一个自娱自乐的demo 开发环境 apache-tomcat-6.0.16 Mysql 5.1.11 Jdk 1.6 文件结构如下 --MyGame -----MyGam
💻 JAVA
字号:
package com.hb.base.view.domain;

import java.util.Locale;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Destroy;

import com.hb.base.util.FacesContextUtil;
import com.hb.base.util.SpringContextUtils;
import com.hb.core.bean.BaseBean;

public abstract class AbstractViewBean extends BaseBean {
	private final String USER_INFO = "userInfo";

	/** Bean生命周期中初始化方法 */
	@Create
	public void _create() {
		create();
	}

	/** Bean生命周期中初始化方法 */
	public abstract void create();

	public abstract void init();

	/** Bean生命周期中销毁方法 */
	@Destroy
	public void _destroy() {
		destroy();
	}

	/** Bean生命周期中销毁方法 */
	public abstract void destroy();

	/**
	 * 取得 FacesContext
	 * 
	 * @return FacesContext
	 */
	protected FacesContext getFacesContext() {
		return FacesContextUtil.getFacesContext();
	}

	/**
	 * 取得 RequestParameterMap
	 * 
	 * @return RequestParameterMap
	 */
	@SuppressWarnings("unchecked")
	protected Map getRequestParameterMap() {
		return FacesContextUtil.getRequestParameterMap();

	}

	/**
	 * 取得消息资源
	 * 
	 * @param msgKey 消息Key
	 * @return 消息
	 */
	protected String getMessage(String msgKey) {
		return getMessage(msgKey, null, Locale.CHINA);
	}

	/**
	 * 取得消息资源
	 * 
	 * @param msgKey 消息Key
	 * @param args 消息Param
	 * @return 消息
	 */
	protected String getMessage(String msgKey, Object[] args) {
		return getMessage(msgKey, args, Locale.CHINA);
	}

	/**
	 * 取得消息资源
	 * 
	 * @param msgKey 消息Key
	 * @param args 消息Param
	 * @param locale Locale
	 * @return
	 */
	protected String getMessage(String msgKey, Object[] args, Locale locale) {
		return SpringContextUtils.getMessage(msgKey, args, locale);
	}

	/**
	 * 取得 HttpServletRequest
	 * 
	 * @return HttpServletRequest
	 */
	protected HttpServletRequest getRequest() {
		return FacesContextUtil.getRequest();
	}

	/**
	 * 取得 HttpSession
	 * 
	 * @return HttpSession
	 */
	private HttpSession getSession() {
		return FacesContextUtil.getSession();
	}

	/**
	 * 取得登录用户信息
	 * 
	 * @return 登录用户信息
	 */
	protected UserInfoSessionBean getUserInfo() {
		return (UserInfoSessionBean) getSession().getAttribute(USER_INFO);
	}

	/**
	 * 取得ViewBean
	 * 
	 * @param beanName bean名称
	 * @return ViewBean
	 */
	protected Object getViewBean(String beanName) {
		return FacesContextUtil.getViewBean(beanName);
	}

	/**
	 * 保存登录用户信息
	 * 
	 * @param userInfo 登录用户信息
	 * @return 执行结果
	 */
	protected boolean saveUserInfo(UserInfoSessionBean userInfo) {
		HttpSession session = getSession();
		if (session != null) {
			session.setAttribute(USER_INFO, userInfo);
			return true;
		}
		return false;
	}

	/**
	 * 删除登录用户信息
	 * 
	 * @param userInfo 登录用户信息
	 * @return 执行结果
	 */
	protected boolean removeUserInfo() {
		HttpSession session = getSession();
		if (session != null) {
			session.removeAttribute(USER_INFO);
			return true;
		}
		return false;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -