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

📄 loginbean.java

📁 HR系统模拟企业对内部职员的管理
💻 JAVA
字号:
/*$Id: LoginBean.java,v 1.1 2008/07/15 03:38:22 liqi Exp $ *-------------------------------------- * Apusic (Kingdee Middleware) *--------------------------------------- * Copyright By Apusic ,All right Reserved * author   date   comment * chenhongxin  2008-4-14  Created*/package org.operamasks.example.ejb.hr.litebean;import java.awt.Graphics;import java.util.List;import java.util.Map;import javax.faces.context.FacesContext;import org.operamasks.example.ejb.hr.constants.IUserConstants;import org.operamasks.example.ejb.hr.entity.User;import org.operamasks.example.ejb.hr.service.ServiceBean;import org.operamasks.example.ejb.hr.util.Util;import org.operamasks.faces.annotation.Action;import org.operamasks.faces.annotation.BeforeRender;import org.operamasks.faces.annotation.Bind;import org.operamasks.faces.annotation.LocalString;import org.operamasks.faces.annotation.ManagedBean;import org.operamasks.faces.annotation.ManagedBeanScope;import org.operamasks.faces.annotation.ManagedProperty;import org.operamasks.faces.annotation.Required;import org.operamasks.faces.component.widget.UIDrawImage;/** * 登陆页面托管Bean * @author chenhongxin */@ManagedBean(name="loginBean", scope=ManagedBeanScope.REQUEST)public class LoginBean {		/**	 * 注入服务提供Bean,该Bean提供各种的业务操作对象	 */	@ManagedProperty("#{serviceBean}")	private ServiceBean service;		/**	 * 国际化资源串	 */	@LocalString	private Map<String, String> messages;		/**	 * 登陆名称	 */	@Required(message = "#{this.messages.nameIsRequired}")	@Bind(id="name", attribute="value")	private String name;		/**	 * 登陆密码	 */	@Required(message = "#{this.messages.pwdIsRequired}")	@Bind(id="password", attribute="value")	private String password;		/**	 * 验证码	 */	@Required(message = "#{this.messages.validateCodeIsRequired}")	@Bind(id="validateCode", attribute="value")	private String validateCode;		/**	 * 登陆提示	 */	@Bind(id = "tips", attribute = "value")	private String tips;		/**	 * 页面脚本回调	 */	@Bind(id="scripter", attribute="script")	private String scripter;		@BeforeRender	void beforeRender(boolean isPostback) {		if(!isPostback) {			createValidateCode();		}	}		/**	 * 创建验证码	 */	private void createValidateCode() {		Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();		String randCode = Util.getRandom(4);		session.put(IUserConstants.LOGIN_VALIDATE_CODE, randCode);	}		/**	 * 页面DrawImage组件draw属性绑定的绘图操作函数	 * @param g Graphics	 * @param width 图片宽度	 * @param height 图片高度	 */	public void draw(Graphics g, int width, int height) {		Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();		String randomCode = (String)session.get(IUserConstants.LOGIN_VALIDATE_CODE);				if (randomCode != null) {			Util.drawRandomPicture(g, width, height, randomCode);		}	}		@Bind(id="validateImg", attribute="binding")	private UIDrawImage validateImg;		/**	 * 绑定页面id为validateImg的DrawImage组件的onclick事件,	 * 实现验证码图片重新刷新	 */	@Action(id="validateImg", event="onclick", immediate=true)	public void change() {		createValidateCode();		validateImg.refresh();	}	/**	 * 绑定页面的id为loginBtn的Button组件的点击事件,	 * 进行登陆验证	 */	@Action(id="loginBtn")	public void loginBtn() {		Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();		String randomCode = (String)session.get(IUserConstants.LOGIN_VALIDATE_CODE);		if(!randomCode.equals(validateCode)) {			//获得验证码错误提示信息的国际化资源串			tips = messages.get("LoginBean.tips.validateCodeWrong");			return;		}				List<User> users = service.getUserService().findUserByName(name);		for(User user : users) {			String password = user.getPassword();			if(password == null || password.equals(this.password)) {				//如果密码为空或者密码匹配则使用js脚本回调执行转向				session.put(IUserConstants.USER_BEAN, user);				scripter = "location.href='module/index.faces';";				return;			}		}		//获得用户不存在或密码错误提示信息的国际化资源串		tips = messages.get("LoginBean.tips.nouser");;	}		}

⌨️ 快捷键说明

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