Social networks
You can find me on:
   
Open sharing content

These articles are available under Creative Commons license BY-SA-3.0

Archive for March, 2014

 public void alternateGreenAndWhiteRows(XSSFSheet sheet) {

        SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
        ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule("MOD(ROW(),2)");
        PatternFormatting fill1 = rule1.createPatternFormatting();
        fill1.setFillBackgroundColor(IndexedColors.LIGHT_GREEN.index);
        fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

        CellRangeAddress[] regions = {
                CellRangeAddress.valueOf("A1:Z100")
        };

        sheetCF.addConditionalFormatting(regions, rule1);

    }

With the rendered tag set to false (rendered=”false”) it doesn´t work at the moment (it has been reported as bug lately: https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/209), but you can make it with css like this:

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

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;

    addCoverType(workbook,book);

}

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++) {
        sheet.getRow(i).createCell(4);
        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! 😀

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:

@Before
public void refreshPage() {
    driver.navigate().refresh();
}

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.