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

📄 userbean.java

📁 spring+Hibernate +jsf
💻 JAVA
字号:
package login.view.bean;

import java.util.List;

import login.model.bussinessobjects.User;
import login.view.util.FacesUtils;

import org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException;

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;

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

	/**
	 * Backing bean action to login a user.
	 * 
	 * @return the navigation result
	 */
	public String loginAction() {
		try {
			User user = this.serviceLocator.getUserService().login(
					this.username, this.password);

			if (user != null) {
				this.loggedIn = true;

				return NavigationResults.SUCCESS;
			} else {
				this.loggedIn = false;

				String msg = "Incorrect password ";
				FacesUtils.addErrorMessage(msg + ", please try again.");
				this.log.debug(msg);

				return NavigationResults.RETRY;
			}
		} catch (HibernateObjectRetrievalFailureException he) {
			String msg = "Non-existing username ";
			this.log.info(msg);
			FacesUtils.addErrorMessage(msg + ", please try again.");

			return NavigationResults.RETRY;
		} catch (Exception e) {
			this.log.error("Could not log in user.", e);
			FacesUtils.addInfoMessage("Could not log in user: Internal Error");

			return NavigationResults.FAILURE;
		}
	}

	/**
	 * The backing bean action to logout a user.
	 * 
	 * @return the navigation result
	 */
	public String logoutAction() {
		this.clear();
		this.log.debug("Logout successfully.");

		return NavigationResults.HOME;
	}

	public List getAll() {
		return this.serviceLocator.getUserService().getAll();
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String newUsername) {
		this.username = newUsername;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String newPassword) {
		this.password = newPassword;
	}

	public boolean getLoggedIn() {
		return this.loggedIn;
	}

	public void setLoggedIn(boolean newLoggedIn) {
		this.loggedIn = newLoggedIn;
	}

	public String getDummyVariable() {
		return null;
	}

	private void clear() {
		this.username = null;
		this.password = null;
		this.loggedIn = false;
	}
}

⌨️ 快捷键说明

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