Package eja.controllers

Source Code of eja.controllers.UserController

package eja.controllers;

import eja.ejb.dao.RoleDao;
import eja.ejb.dao.UserDao;
import eja.ejb.entities.User;
import eja.ejb.entities.UserRole;
import java.util.Collection;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
*
* @author fero
*/
@ManagedBean
@RequestScoped
public class UserController {

    @EJB
    private UserDao _userDao;
    @EJB
    private RoleDao _roleDao;

    @ManagedProperty("#{param['login']}")
    private String login;
    private String password;
    private String name;
    private String surname;
    private Collection<UserRole> roles;



    private User _user;

    /** Creates a new instance of User */
    public UserController() {
    }

    public Collection<User> getAllUsers() {
        return this._userDao.getAllUsers();
    }

    public Collection<UserRole> getAllRoles() {
        return this._roleDao.getAllRoles();
    }

    public String edit() {
        this._user = (!this.login.equals("")) ? this._userDao.getUserByLogin(this.login) : new User();
        this._user.setLogin(this.login);
        this._user.setPassword(this.password);
        this._user.setName(this.name);
        this._user.setSurname(this.surname);
        this._user.setRoles(this.roles);

        this._userDao.saveUser(this._user);
        return "user-details";
    }

    public User getUser() {
        return this._user;
    }

    public void load() {
        this._user = this._userDao.getUserByLogin(this.login);
        this.login = this._user.getLogin();
        this.password = this._user.getPassword();
        this.name = this._user.getName();
        this.surname = this._user.getSurname();
        this.roles = this._user.getRoles();
    }

    // Getters & Setters
    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        if (login == null || login.equals("")) {
            return;
        }

        this.login = login;
        this.load();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

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

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public Collection<UserRole> getRoles() {
        return roles;
    }

    public void setRoles(Collection<UserRole> roles) {
        this.roles = roles;
    }

   
}
TOP

Related Classes of eja.controllers.UserController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.