/*
 * 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 managed_beans;

import entities.Knjiga;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Named;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.RequestScoped;
import javax.faces.annotation.FacesConfig;
import util.dao.KnjigaDAO;
import util.dao.PisacDAO;

/**
 *
 * @author jelic
 */
@Named(value = "knjigeManagedBean")
@RequestScoped
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class KnjigeManagedBean {

    /**
     * Creates a new instance of KnjigeManagedBean
     */
    public KnjigeManagedBean() {
    }
    
    private List<Knjiga> knjige;

    public List<Knjiga> getKnjige() {
        return knjige;
    }

    public void setKnjige(List<Knjiga> knjige) {
        this.knjige = knjige;
    }
    
    @PostConstruct
    public void postaviKnjige(){
        knjige = new PisacDAO().knjigeOdPisca((String) util.SessionUtils.getSession().getAttribute("korisnik"));
    }
    
    private Knjiga k = new Knjiga();

    public Knjiga getK() {
        return k;
    }

    public void setK(Knjiga k) {
        this.k = k;
    }
    
    public void dodajKnjigu(){
        k.setPisac((String) util.SessionUtils.getSession().getAttribute("korisnik"));
        new KnjigaDAO().dodajKnjigu(k);
        postaviKnjige();
    }
}
