beans.ReviewsBeans.java Source code

Java tutorial

Introduction

Here is the source code for beans.ReviewsBeans.java

Source

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

import database.Projects;
import database.Reviews;
import facades.ReviewsFacade;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;

/**
 *
 * @author Marko
 */
@ManagedBean
@SessionScoped
public class ReviewsBeans {
    @EJB
    private ReviewsFacade reviewsFacade;

    private List<Reviews> reviews;

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

    @PostConstruct
    public void afterConstructor() {
        System.out.println("TestUserConstruct");
        refreshList();
    }

    public void refreshList() {
        this.reviews = reviewsFacade.findAll();

    }

    public List<Reviews> getReviews() {
        return reviews;
    }

    public void setReviews(List<Reviews> reviews) {
        this.reviews = reviews;
    }

    public void postProcessXLS(Object document) {
        HSSFWorkbook wb = (HSSFWorkbook) document;
        HSSFSheet sheet = wb.getSheetAt(0);
        CellStyle style = wb.createCellStyle();
        style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());

        for (Row row : sheet) {
            for (Cell cell : row) {
                cell.setCellValue(cell.getStringCellValue().toUpperCase());
                cell.setCellStyle(style);
            }
        }
    }

}