Index: /raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/reports/GraphAndChartPDFReportGenerator.java
===================================================================
--- /raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/reports/GraphAndChartPDFReportGenerator.java	(revision 570)
+++ /raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/reports/GraphAndChartPDFReportGenerator.java	(revision 571)
@@ -105,30 +105,9 @@
     private JasperPrint constructReport(File reportTemplateXMLFile, WebSession session) throws IOException, JRException, ColumnBuilderException {
 	log.info("Constructing Report Using DynamicJasper");
-	// List source = new ArrayList();
-	// BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(),
-	// session.getGraphmodel().getChartOptions());
-	// reportBean.setImage(image);
-	// ArrayList<String> values = new ArrayList();
-	// values.add("One");
-	// values.add("Two");
-	// reportBean.setState(values);
-	// source.add(reportBean);
-	//
-	// DynamicReportBuilder drb = new DynamicReportBuilder();
-	// drb.setTemplateFile(reportTemplateXMLFile.getCanonicalPath());
-	//
-	// drb.addField("image", java.awt.image.BufferedImage.class.getName());
-	//
-	// //session.getGraphmodel().getCurrentTableGraph().ge
-	//
-	// AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state",List.class.getName()).setTitle("State").setWidth(85).build();
-	// drb.addColumn(columnState);
-	// DynamicReport dynamicReport = drb.build();
-	//
-	// JRDataSource ds = new JRBeanCollectionDataSource(source);
-	// JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), ds);
-	String[] columns = new String[session.getGraphmodel().getCurrentTableGraph().getTableSeries().size()+1];
-	columns[0] = "Group";//always group
-	int headerCount=1;
+
+	// construct the table
+	String[] columns = new String[session.getGraphmodel().getCurrentTableGraph().getTableSeries().size() + 1];
+	columns[0] = "Group";// always group
+	int headerCount = 1;
 	for (TableSeries tseries : session.getGraphmodel().getCurrentTableGraph().getTableSeries()) {
 	    columns[headerCount++] = tseries.getSeriesLabel();
@@ -137,12 +116,10 @@
 	Object[][] data = new Object[maxNoRows(session.getGraphmodel().getCurrentTableGraph())][columns.length];
 
-
-
-	int rowCount=0;
+	int rowCount = 0;
 	for (ManyRow mrow : session.getGraphmodel().getCurrentTableGraph().getRowsForView()) {
-	    data[rowCount][0]=mrow.getGroupLabel();
-	    Iterator<?> it =mrow.getValues().iterator();
-	    headerCount=1;
-	    while (it.hasNext()){
+	    data[rowCount][0] = mrow.getGroupLabel();
+	    Iterator<?> it = mrow.getValues().iterator();
+	    headerCount = 1;
+	    while (it.hasNext()) {
 		String value = it.next().toString();
 		data[rowCount][headerCount++] = value;
@@ -150,5 +127,5 @@
 	    rowCount++;
 	}
-	log.debug("{}",Arrays.toString(data));
+	log.debug("{}", Arrays.toString(data));
 
 	DynamicTableModel model = new DynamicTableModel();
@@ -156,27 +133,22 @@
 	model.setData(data);
 
-	BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(),session.getGraphmodel().getChartOptions());
-
-	//FastReportBuilder drb = new FastReportBuilder();
+	// construct report and set the template
 	DynamicReportBuilder drb = new DynamicReportBuilder();
 	drb.setTemplateFile(reportTemplateXMLFile.getCanonicalPath());
-//	drb.addField("image", java.awt.image.BufferedImage.class.getName());
-
-	Style columDetail = new Style();
-	columDetail.setBorder(Border.THIN);
+
 	Style columDetailWhite = new Style();
 	columDetailWhite.setBorder(Border.THIN);
 	columDetailWhite.setBackgroundColor(Color.WHITE);
+	columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER);
 	Style columDetailWhiteBold = new Style();
 	columDetailWhiteBold.setBorder(Border.THIN);
 	columDetailWhiteBold.setBackgroundColor(Color.WHITE);
+
+
+
 	Style titleStyle = new Style();
-	titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true));
-	Style numberStyle = new Style();
-	numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
-	Style amountStyle = new Style();
-	amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
-	amountStyle.setBackgroundColor(Color.cyan);
-	amountStyle.setTransparency(Transparency.OPAQUE);
+	titleStyle.setFont(new Font(12, Font._FONT_VERDANA, true));
+	titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
+	titleStyle.setBorder(Border.THIN);
 	Style oddRowStyle = new Style();
 	oddRowStyle.setBorder(Border.NO_BORDER);
@@ -188,41 +160,37 @@
 	String[] headings = model.getColumnNames();
 	for (int i = 0; i < headings.length; i++) {
-	    String key = headings[i];
-	    AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhite).build();
-	    drb.addColumn(column);
-
-	}
-	//drb.setTitle("Sample Report").setTitleStyle(titleStyle).setTitleHeight(new Integer(30)).setSubtitleHeight(new Integer(20)).setDetailHeight(new Integer(15))
-	//	.setPrintBackgroundOnOddRows(true).setOddRowBackgroundStyle(oddRowStyle).setColumnsPerPage(new Integer(1)).setUseFullPageWidth(true).setColumnSpace(new Integer(5));
-	drb.setPrintBackgroundOnOddRows(true).setOddRowBackgroundStyle(oddRowStyle).setColumnsPerPage(new Integer(1)).setUseFullPageWidth(true).setColumnSpace(new Integer(5));
-	
-//	ArrayList beans = new ArrayList();
-//	SimpleRowBean a1 = new SimpleRowBean("header1","row1","VALUE1");
-//	SimpleRowBean a2 = new SimpleRowBean("header2","row1","VALUE2");
-//	SimpleRowBean a3 = new SimpleRowBean("header3","row1","VALUE3");
-//	beans.add(a1);
-//	beans.add(a2);
-//	beans.add(a3);
-//
-//	SimpleRowBean b1 = new SimpleRowBean("header1","row2","VALUE1");
-//	SimpleRowBean b2 = new SimpleRowBean("header2","row2","VALUE2");
-//	SimpleRowBean b3 = new SimpleRowBean("header3","row2","VALUE3");
-//	beans.add(b1);
-//	beans.add(b2);
-//	beans.add(b3);
-	
-	reportBean.setImage(image);
-	//beans.add(reportBean);
-	//JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(beans);
+	    if (i == 0) {
+		// group category
+		String key = headings[i];
+		AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhiteBold).build();
+		column.setHeaderStyle(titleStyle);
+		drb.addColumn(column);
+	    } else {
+		String key = headings[i];
+		AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhite).build();
+		column.setHeaderStyle(titleStyle);
+		drb.addColumn(column);
+	    }
+
+	}
+
+	drb.setPrintBackgroundOnOddRows(true);
+	drb.setOddRowBackgroundStyle(oddRowStyle);
+	drb.setColumnsPerPage(new Integer(1));
+	drb.setUseFullPageWidth(true);
+	drb.setColumnSpace(new Integer(5));
+	drb.setDetailHeight(new Integer(15));
+
+	// add any additional parameters that are mapped to the template
+	BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(), session.getGraphmodel().getChartOptions());
+
 	Map parameters = new HashMap();
 	parameters.put("image", image);
-	log.debug("Map: "+parameters);
-//	JasperReport jasperReport = JasperCompileManager.compileReport(reportTemplateXMLFile.getCanonicalPath());
-	
-//	JasperPrint jp = JasperFillManager.fillReport(jasperReport, parameters, ds);
+	parameters.put("subtitle", session.getGraphmodel().getSelectedStatisticalUnit().getStatisticalUnitInformation().getStatisticParameters().getPresentation().getGraphTitle());
+	log.debug("Map: " + parameters);
 
 	DynamicReport dr = drb.build();
 	JRDataSource ds = new JRTableModelDataSource(model);
-	JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds,parameters);
+	JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds, parameters);
 	return jp;
     }
@@ -234,9 +202,9 @@
     private int maxNoRows(RaptorTableChartModel currentTableGraph) {
 	int maxRows = 0;
-	 for (TableSeries tseries :currentTableGraph.getTableSeries()){
-	     if (tseries.getRows().size()>maxRows)
-		 maxRows=tseries.getRows().size();
-	 }
-	 return maxRows;
+	for (TableSeries tseries : currentTableGraph.getTableSeries()) {
+	    if (tseries.getRows().size() > maxRows)
+		maxRows = tseries.getRows().size();
+	}
+	return maxRows;
     }
 
Index: /raptor-web/trunk/src/main/webapp/report-templates/generic-report.xml
===================================================================
--- /raptor-web/trunk/src/main/webapp/report-templates/generic-report.xml	(revision 570)
+++ /raptor-web/trunk/src/main/webapp/report-templates/generic-report.xml	(revision 571)
@@ -1,68 +1,83 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DataSourceReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
-	<style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
-	<style name="Sans_Bold" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
-	<style name="Sans_Italic" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/>
-	<parameter name="image" class="java.awt.Image"/>
-	<field name="description" class="java.lang.String"/>
+    <!--  This report is augmented with a table by DynamicJasper. DynamicJasper prohibits the use of the following
+    aspects of Jasper report templates:
+      The template must not have groups, DynamicJAsper will create them if necessary.
+	   The detail band must be empty: DynamicJasper will work in the detail band, any previously existing element will be deleted.
+	   One template per page size and orientation will be needed: This is because DJ knows how to arrange the element he creates, but not the existing ones.
+	   The following options will be always overwritten by the dynamic report
+	       number of columns
+	       When-No-Data behavior
+	       When-Resource-Missing behavior
+	       Title start on new page flag (false by default)
+	       Ignore Pagination flag (false by default)
+	       Detail Band Split allowed flag (true by default)
+	       Summary start on new page flag (false by default)
+     -->
+    <parameter name="image" class="java.awt.Image"/>
 
-	 <title>
- <!--  <band height="50">
-      <staticText>
-        <reportElement x="0" y="0" width="180" height="15"/>
-        <textElement>
-        	<font fontName="DejaVu Sans" size="9"/>
-        </textElement>
-        <text><![CDATA[RaptorWeb Report]]></text>
-      </staticText> 
-    </band>-->
-    <band height="600">
-			<staticText>
-				<reportElement x="0" y="10" width="311" height="20"/>
-				<textElement textAlignment="Center">
-					<font fontName="DejaVu Sans" size="20"/>
-				</textElement>
-				<text><![CDATA[Report Title]]></text>
-			</staticText>
-			<image scaleImage="RetainShape" hAlign="Center" isUsingCache="true" isLazy="true">
-				<reportElement x="0" y="30" width="500" height="500"/>
-				<imageExpression class="java.awt.Image"><![CDATA[$P{image}]]></imageExpression>
-			</image>
-		</band>
-  	</title>
-  	<pageHeader>
-    <band/>
-  	</pageHeader>
-  	
+    <!--  The integration of a chart and table with dynamic Jasper requires the chart (or image) to be placed in the pages
+    Title area  -->
+    <title>
+    <band height="72">
+            <frame>
+                <reportElement mode="Opaque" x="-20" y="-20" width="540" height="92" backcolor="#006699"/>
+                <staticText>
+                    <reportElement x="20" y="20" width="234" height="43" forecolor="#FFFFFF"/>
+                    <textElement>
+                        <font size="34" isBold="true"/>
+                    </textElement>
+                    <text><![CDATA[Report]]></text>
+                </staticText>
+                <textField>
+                    <reportElement x="70" y="43" width="465" height="20" forecolor="#FFFFFF"/>
+                    <textElement textAlignment="Right">
+                        <font size="13" isBold="false"/>
+                    </textElement>
+                    <textFieldExpression><![CDATA[$P{subtitle}]]></textFieldExpression>
+                </textField>
+            </frame>
+            <image scaleImage="RetainShape" hAlign="Center" isUsingCache="true" isLazy="true">
+                <reportElement x="0" y="100" width="500" height="500"/>
+                <imageExpression class="java.awt.Image"><![CDATA[$P{image}]]></imageExpression>
+            </image>
+        </band>
+     </title>
+
+
 	<detail>
 		<band>
-			<staticText>
-        <reportElement x="0" y="0" width="40" height="15"/>
-        <textElement>
-            <font fontName="DejaVu Sans" size="8"/>
-        </textElement>
-        <text><![CDATA[Page:]]></text>
-      </staticText>
+            <!-- This band in the detail is where DynamicJasper will add the table, please leave -->
 		</band>
-		
+
 	</detail>
 
-	<pageFooter>
-    <band height="15">
-      <staticText>
-        <reportElement x="0" y="0" width="40" height="15"/>
-        <textElement>
-            <font fontName="DejaVu Sans" size="8"/>
-        </textElement>
-        <text><![CDATA[Page:]]></text>
-      </staticText>
-      <textField>
-        <reportElement x="40" y="0" width="100" height="15"/>
-        <textElement>
-        	<font fontName="DejaVu Sans" size="8"/>
-        </textElement>
-        <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
-      </textField>
-    </band>
-  </pageFooter>
+    <pageFooter>
+        <band height="17">
+            <textField>
+                <reportElement mode="Opaque" x="0" y="4" width="480" height="13" backcolor="#E6E6E6"/>
+                <textElement textAlignment="Right">
+                    <font fontName="DejaVu Sans" size="8"/>
+                </textElement>
+                <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
+            </textField>
+            <textField evaluationTime="Report">
+                <reportElement mode="Opaque" x="480" y="4" width="40" height="13" backcolor="#E6E6E6"/>
+                <textElement>
+                    <font fontName="DejaVu Sans" size="8"/>
+                </textElement>
+                <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
+            </textField>
+            <textField pattern="EEEEE dd MMMMM yyyy">
+                <reportElement x="0" y="4" width="100" height="13"/>
+                <textElement>
+                    <font fontName="DejaVu Sans" size="8"/>
+                </textElement>
+                <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
+            </textField>
+        </band>
+    </pageFooter>
+    <summary>
+        <band/>
+    </summary>
 </jasperReport>
