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

📄 userbean.java

📁 一个ssh结构组成 的BS开发
💻 JAVA
字号:
package cn.hxex.library.view.bean;

import cn.hxex.library.exception.LibraryException;
import cn.hxex.library.model.User;
import cn.hxex.library.view.util.FacesUtils;

/**
 * 用户Bean
 * 
 * @author galaxy
 *
 */
public class UserBean extends BaseBean
{
	//	the username of the current user
	private String username;

	//the password of the current user
	private String password;

	//whether or not the user is logged in
	private boolean loggedIn;

	
	/**
	 * @return Returns the loggedIn.
	 */
	public boolean isLoggedIn()
	{
		return loggedIn;
	}

	/**
	 * @param loggedIn The loggedIn to set.
	 */
	public void setLoggedIn(boolean loggedIn)
	{
		this.loggedIn = loggedIn;
	}

	/**
	 * @return Returns the password.
	 */
	public String getPassword()
	{
		return password;
	}

	/**
	 * @param password The password to set.
	 */
	public void setPassword(String password)
	{
		this.password = password;
	}

	/**
	 * @return Returns the username.
	 */
	public String getUsername()
	{
		return username;
	}

	/**
	 * @param username The username to set.
	 */
	public void setUsername(String username)
	{
		this.username = username;
	}

	/**
	 * Default constructor.
	 */
	public UserBean()
	{
		this.clear();
		this.logger.debug("UserBean is created");
	}

	public String getDummyVariable() 
	{
		return null;
	}
	
	/**
	 * Backing bean action to login a user.
	 * 
	 * @return the navigation result
	 */
	public String loginAction()
	{
		try
		{
			User user = this.getServiceLocator().getUserService().login( 
					this.username, this.password );
			this.username = user.getUsername();
			this.loggedIn = true;
			return NavigationResults.SUCCESS;
		} 
		catch (LibraryException e)
		{
			this.loggedIn = false;
			FacesUtils.addErrorMessageById( e.getMessage() );
			return NavigationResults.RETRY;
		}
	}

	/**
	 * The backing bean action to logout a user.
	 * 
	 * @return the navigation result
	 */
	public String logoutAction() 
	{
		this.clear();
		this.logger.debug("Logout successfully.");
		
		return NavigationResults.HOME;
	}
	
	private void clear()
	{
		this.username = null;
		this.password = null;
		this.loggedIn = false;
	}
}

⌨️ 快捷键说明

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