views:

130

answers:

1

Hi,

I want to generate a pdf report, where a column(or cell/field) is left blank(empty) on purpose. This column actually does have a value but, I'm choosing not to display it. The column title still needs to be displayed.

Example of where this could be useful:

  • Blank(empty) column: A comments or notes column down one side of a report.
  • Blank(empty) cell: A sudoku puzzle print-out.

Much appreciated. DynamicJasper is Awesome! Thanks to the dj-team.

Regards, Pete

A: 

Hi There,

Glad to announce, solution found for adding an 'empty' column - and in short, it's to create a customExpression.

def cb = ColumnBuilder.getInstance()
cb = cb.setTitle("Notes")
cb = cb.setCustomExpression(new BlankExpression())
AbstractColumn columnNotes = cb.build()

Then add it to the rest of the report.

Class BlankExpression is

public class BlankExpression implements CustomExpression {

    public BlankExpression() {    }

    public Object evaluate(Map fields, Map variables, Map parameters) {
        return " ";
    }

    public String getClassName() {
        return String.class.getName();
    }
}

But there are a few issues relating to the use of customExpressions and grails.

1st issue: "getNew()" - The examples provided on the DJ website all use "getNew()" http://dynamicjasper.sourceforge.net/docs/HOWTO%20Create%20Custom%20Expressions.html is an example of DynamicJasper v3.1.3 where as the Grails plugin is based on v.3.0.6 which only has a getInstance() method (deprecated in 3.1.3)

2nd issue: As far as I can see, groovy doesn't allow java-style inline class implementations, thus forcing us to create a separate class file. But this is not a big problem. I might be wrong about this, and please correct me.

Hope this helps you too.

Regards, Pete

petejoe