Null pointer exception thrown when displaying dynamic columns in PDF, Excel
exports
-----------------------------------------------------------------------------------
Key: DISPL-618
URL: http://jira.codehaus.org/browse/DISPL-618
Project: DisplayTag
Issue Type: Bug
Components: Export
Affects Versions: 1.2
Reporter: Mrudula V
Priority: Critical
Fix For: 1.2
Attachments: Exporttest.jsp
A Map has been taken to store the dynamic values. In the jsp side, i am
iterating the map to generate dynamic columns as given below :
--------------------------------------------------------------------Display tag
in
jsp-----------------------------------------------------------------------------------------------
<display:table style="width:80%" id="row" name="test" class="dataTable"
cellspacing="1" cellpadding="2" export="true" pagesize="10"
decorator="com.jamocha.util.Wrapper">
<display:caption media="pdf excel html" class="header">Student
List</display:caption>
<display:column property="name" title="Name" class="text"
headerClass="text" sortable="true"/>
<display:column property="studyClass" title=" Study Class" class="text"
headerClass="text" sortable="true"/>
<display:column property="totalMarks" title="Total Marks" class="numeric"
headerClass="numeric" media="html" sortable="true"/>
<display:column property="totalMarks" title="Total Marks" class="numeric"
media="pdf" headerClass="textAlignment" sortable="true"/>
<display:column property="percentage" title="Percentage" class="numeric"
headerClass="numeric" sortable="true"/>
<%
int rowNumberInt = 0;
Student reportVO = l.get((++rowNumberInt) -1);
for(int i =1; i<=10;i++)
{
String avgVal = reportVO.getAvgValueMap().get(i)+"";%>
<display:column value="<%=avgVal%>" title="<%="Avg_"+i%>"
format="{0,number,00.00}" headerClass="numeric" maxLength="10" class="numeric"
sortable="true"/>
<% }%>
</display:table>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The code is working fine for Html. i.e the dynamic columns are getting
generated in Html.
Whereas, for exports we have written our own class which extends
BinaryExportView Class.
In pdf to generate the dynamic columns we have written a code something similar
to as given below :
------------------------------------------------------------------In pdf
-------------------------------------------------------------------------------------------------------------
private void generateTableModelFromRequest()
{
// creating new table model n setting properties to old one
try
{
TableProperties tableprop = this.model.getProperties();
List exportList = (List)
this.model.getTableDecorator().getPageContext().getRequest().getAttribute(this.model.getId());
TableModel tableModel = new TableModel(tableprop,
"ISO-8859-1", this.model.getTableDecorator().getPageContext());
// tableModel.setCaption(model.getCaption());
//
tableModel.setTableDecorator(model.getTableDecorator());
tableModel.setMedia(this.model.getMedia());
// Adding header cell from existing model to our new
tableModel and getting method names
Iterator itrHeader =
this.model.getHeaderCellList().iterator();
String[] methodArray = new
String[this.model.getNumberOfColumns()];
int count = 0;
while (itrHeader.hasNext())
{
HeaderCell headercell = new HeaderCell();
headercell = (HeaderCell) itrHeader.next();
tableModel.addColumnHeader(headercell);
if (headercell.getBeanPropertyName() == null)
{
methodArray[count++] = null;
}
else
{
methodArray[count++] = "get" +
StringUtils.capitalize(headercell.getBeanPropertyName());
}
}
// iterating through new list and creating cell and
rows and adding to new table model
int rowNo = 1;
Iterator expotListItr = exportList.iterator();
org.displaytag.model.Cell cell = null;
Row row = null;
while (expotListItr.hasNext())
{
Object exportRowObj = expotListItr.next();
row = new Row(exportRowObj, rowNo);
ColumnIterator columnIterator =
row.getColumnIterator(this.model.getHeaderCellList());
for (int i = 0; i <
tableModel.getNumberOfColumns(); i++)
{
Object cellValue = null;
Column column = null;
if (columnIterator.hasNext())
{
try
{
column =
columnIterator.nextColumn();
}
catch (Exception e)
{
ManagerLogger.out.error("Exception" + e);
}
}
if (methodArray[i] != null)
{
cellValue =
processMethodOnObject(exportRowObj, methodArray[i]);
System.out.println("Cell value
::::" + cellValue);
}
else if (column != null)
{
cellValue =
column.getValue(false);
System.out.println("Dynamic
Cell value ::::" + cellValue);
}
cell = new
org.displaytag.model.Cell(cellValue);
row.addCell(cell);
columnIterator =
row.getColumnIterator(this.model.getHeaderCellList());
for (int j = 0; j <= i; j++)
{
if (columnIterator.hasNext())
{
columnIterator.nextColumn();
}
}
}
tableModel.addRow(row);
}
// setting the previous table model(model)row list page
to new table model's(tableModel)
// full page.
// This will export entire data which is in new table
model(tableModel)
this.model.setRowListPage(tableModel.getRowListFull());
}
catch (Exception e)
{
ManagerLogger.out.error("Exception", e);
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
With the above code though the dynamic columns are getting displayed in PDf and
Excel export, in the tomcat console a "NULLPointer Exception" is getting thrown
near the line:
cellValue = column.getValue(false);
If the boolean value is given as true, then there is no NULL Pointer exception
, but columns in pdf and excel are showing empty.
It would be great if you can find a solution for this. This is the first time
that I am raising an issue in forum.So, I have don't have any idea of what all
the files I need to attach for you to understand the problem much easier.Please
suggest if any fursther details are required.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
displaytag-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel