/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sikd.ikonsol.ctrl;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import sikd.ikonsol.ejb.session.UserEjbHome;
import sikd.ikonsol.model.User;

/**
 *
 * @author Imam Bhoim
 */
@ViewScoped
@Named(value = "userBeanCtrl")
public class UserBeanCtrl implements Serializable {
    
    User user;
    User obj;
    private List<User> list;

    private String username;
    private String password;
    private int status;

    @EJB
    UserEjbHome userEjbHome;

    @PostConstruct
    public void init() {

        list = userEjbHome.findAll();

        //obj = periodeEjbHome.findByKode("22");
        //periode = periodeEjbHome.createNew();
    }

    public void add() {

        user = userEjbHome.createNew();

    }
//
//    public String save() {
//
//        User a = new User();
//        try {
//            a = periodeEjbHome.findByKode(a.getKode());
//            if (a == null) {
//                periodeEjbHome.save(periode);
//
//                PrimeFaces.current().executeScript("PF('wg_entryform').hide()");
//                PrimeFaces.current().ajax().update(":master:dtperiod");
//
//                list = periodeEjbHome.findAll();
//                //this.list = service.findAll();
//            }
//        } catch (Exception ex) {
//            System.out.println("GAGAL!");
////            FacesContext.getCurrentInstance().addMessage(null, 
////                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Info!", "Kode Sudah Ada"));
////            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info!", "Kode Sudah Ada");
////            FacesContext.getCurrentInstance().addMessage(null, message);
//            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, 
//                    "Info", "Kode Sudah Ada");
//            PrimeFaces.current().dialog().showMessageDynamic(message);
//        }
//
//        return "index?faces-redirect=true";
//        // simpan
//    }
//
//    public String update() {
//
//        periodeEjbHome.update(obj);
//
//        PrimeFaces.current().executeScript("PF('wg_entryform_ubah').hide()");
//        PrimeFaces.current().ajax().update(":master:dtperiod");
//
//        list = periodeEjbHome.findAll();
//        // this.list = service.findAll();
//        return "index?faces-redirect=true";
//    }
//
    public void edit(int id) {
        //obj = service.findByID(Integer.parseInt(id));
     //   obj = periodeEjbHome.findByKode(kode);

    }
//
    public void delete(int id) {
        //obj = service.findByID(Integer.parseInt(id));
        //obj = periodeEjbHome.findByKode(kode);
//        periodeEjbHome.delete(kode);
//        PrimeFaces.current().ajax().update(":master:dtperiod");
//        list = periodeEjbHome.findAll();
        // this.list = service.findAll();

    }
    

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getObj() {
        return obj;
    }

    public void setObj(User obj) {
        this.obj = obj;
    }

    public List<User> getList() {
        return list;
    }

    public void setList(List<User> list) {
        this.list = list;
    }

    public String getUsername() {
        return username;
    }

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

    public String getPassword() {
        return password;
    }

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

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
    
    
}
