Archive for March, 2014

APACHE POI Excel: Alternate green and white rows

 public void alternateGreenAndWhiteRows(XSSFSheet sheet) {

        SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
        ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("MOD(ROW(),2)");
        PatternFormatting fill1 = rule1.createPatternFormatting();

        CellRangeAddress[] regions = {

        sheetCF.addConditionalFormatting(regions, rule1);


Primefaces 4.0 DataExporter: How to add columns to excel report only

With the rendered tag set to false (rendered=”false”) it doesn´t work at the moment (it has been reported as bug lately:, but you can make it with css like this:

<p:column headerText="#{msg['book.coverType']}" style="display:none;">
         <h:outputText value="#{book.coverType}"/>

Another solution is to add a post process method in your managed bean and add the column from there:

public void postProcessXLS(Object document) { log.debug("post processing Excel");
    HSSFWorkbook workbook = (HSSFWorkbook) document;



You can write the method like:

public void addCoverType(HSSFWorkbook workbook, List<Book> books) {

    HSSFSheet sheet = workbook.getSheetAt(0);
    HSSFCell cell = null;

 //row 0 is the header (not automatically added by primefaces)
 //add a fifth cell to each row
    for (int i = 1; i<sheet.getLastRowNum() + 1; i++) {
        cell = sheet.getRow(i).getCell(4);
        cell.setCellValue(book.get(i - 1).getCoverType());
    log.debug("cover type added");

If you make sortable column the order will be automatically respected as well! 😀

Selenium Web driver tests fail if run all together

If you write unit tests that must be run like if you had to open/refresh a new browser session each time, you can use a method with before annotations:

public void refreshPage() {

If all tests are individually successful (green) but fail all together, the reason might also been that you need to wait for some resources to be available on the page, so you also need to handle it, setting the timeout like this:

 public WebElement getSaveButton() {
     return findDynamicElementByXPath(By.xpath("//*[@id=\"form:btnSave\"]"), 320);

320 is a long time, but you must make sure that you give enough time to get all that it takes to test.