Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » HTML output in DataItem using Java(How to allow/embed HTML content into a bound DataItem)
icon5.gif  HTML output in DataItem using Java [message #939322] Wed, 10 October 2012 12:44
Doug Schnee is currently offline Doug Schnee
Messages: 1
Registered: October 2012
Junior Member
Hi,

I don't have the opportunity to work on our BIRT projects often and am likely missing something obvious here.

I have a very generic report built using the Java API (BIRT 3.7) and my ultimate goal is to get tabular output within a cell of a table based on the incoming data bound to that cell.

For clarification, the incoming data for any given cell may contain row/column delimited data such as: aa::bb::cc;;xx::yy::zz;; where :: is the column separator and ;; is a row separator. The hope is that within this target cell, based on analysis of that data, we could break it down and represent it as an embedded Grid (or HTML table if it were auto-magically rendered due to knowing it is HTML).


My first approach was to set an expression on the computed column to a JavaScript function and return HTML tags (used a span in my test), the data is not evaluated and printed in raw form on the report. Though the expression invoked the JavaScript properly, this was obviously the wrong approach.

My second approach had me looking at both the ComputedColumn and the DataItem to see if I could tell it that the content would be HTML. I'm unable to set the resultDataSet on anything but a DataItem, and was unable to indicate for the cell handle or DataItem that it will contain HTML.

Here is the code snippet as it is today with the expression invoking structuredData as mentioned in my first approach(engine startup and openReportDesign() is omitted).

allColumns is a list of classes describing the columns to build for the report.

Is there anything that can be done to the ComputedColumn, DataItemHandle or CellHandle to indicate that the data returned from dataSetRow[] is HTML?

Alternatively, is there a way via my structuredData JavaScript method or from the API that I can dynamically put a Grid within the cell and break up the above data to apply to each cell of the inner grid?

Thanks in advance,

Doug

ElementFactory designFactory = designHandle.getElementFactory( );

TableHandle table = designFactory.newTableItem( "table", colCount );
table.setWidth( "100%" );
table.setDataSet( designHandle.findDataSet( dsetName ) );


PropertyHandle computedSet = table.getColumnBindings( );
ComputedColumn  computedColumn = null;

// Add in the columns with content
int dbColIndex = 0;
int tColIndex = 0;
for(ReportColumn col:allColumns) {
	dbColIndex++;
	if (col.getIsDisplayed()) {
		computedColumn = StructureFactory.createComputedColumn();
		computedColumn.setName("col" + tColIndex++);
		
		//sets colName to COLUMN_nnn 
		String colName = String.format(colNameFormat, dbColIndex );
		//default expression to use
		String columnExpr = "structuredData(dataSetRow[\"" + colName + "\"]+'');";
		computedColumn.setExpression(columnExpr);
		computedColumn.setProperty("width", WIDTH_DATA_COL + "in" );
		computedSet.addItem(computedColumn);
	}
}

// table header
RowHandle tableheader = (RowHandle) table.getHeader( ).get( 0 );

int j = 0;
for(ReportColumn col:allColumns) {
	if (col.getIsDisplayed()) {
		LabelHandle label1 = designFactory.newLabel( col.getColumnHeading() );	
		label1.setText(col.getColumnHeading());
		label1.setProperty(Style.FONT_WEIGHT_PROP, "bolder");
		label1.setProperty(Style.PADDING_BOTTOM_PROP, "2pt");
		label1.setProperty(Style.TEXT_ALIGN_PROP, "left");

		CellHandle cell = (CellHandle) tableheader.getCells( ).get( j );
		cell.getContent( ).add( label1 );
		j++;
	}
}
// link the column content to the data set results
RowHandle tabledetail = (RowHandle) table.getDetail( ).get( 0 );
for(int i = 0; i < colCount; i++){
	CellHandle cell = (CellHandle) tabledetail.getCells( ).get( i );
	DataItemHandle data = designFactory.newDataItem( "data_" + i );
	data.setResultSetColumn( "col" + i );
	cell.getContent().add( data );
}

designHandle.getBody().add( table );

Previous Topic:OutOfMemoryError: Java heap space for Birt viewer
Next Topic:XML Datasource multiple call problem [Partly Resolved]
Goto Forum:
  


Current Time: Wed Apr 16 09:30:08 EDT 2014

Powered by FUDForum. Page generated in 0.03560 seconds