I am trying to integrate iText on the lines of example provided by "John
Krasnay" below.
My question is :
1. While iterating over the list of IColumn .....How to I get hold of the
column's headers which I had created earlier using...(See TODO::1)
final List<IColumn> columns = new ArrayList<IColumn>();
columns.add(new PropertyColumn(new Model("Author"), "author") ;
2. Also, How would I get hold of the contents of the column(See
TODO::2)...the way it is now...it always gets the Author property of
POJO.....but i don't understand how to get hold of the contents of current
column being rendered.
~ Any suggestions?
public void generatePDF(OutputStream outputStream, List<IColumn>
columns,
IDataProvider dataProvider) throws IOException {
try {
Document document = new Document(PageSize.A4, 50, 50,
50, 50);
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("C:\\Test2.pdf"));
document.open();
Table t = new Table(columns.size(),
dataProvider.size());
t.setBorderColor(new Color(220, 255, 100));
t.setPadding(1);
t.setSpacing(0);
t.setBorderWidth(0);
for (Iterator iterator = columns.iterator();
iterator.hasNext();) {
//TODO::1: Get hold of column's model and add
to table
// that we are generating with iText
}
Iterator iter = dataProvider.iterator(0,
dataProvider.size());
while (iter.hasNext()) {
Object o = iter.next();
IModel rowModel = dataProvider.model(o);
// Get the POJO for the row....
MyPOJO doc = (MyPOJO) rowModel.getObject();
for (short i = 0; i < columns.size(); i++) {
// TODO::2: How will we know what kind
of property it is...
Cell cell = new Cell(doc.getAuthor());
t.addCell(cell);
}
}
document.add(t);
document.close();
} catch (BadElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Ricky-22 wrote:
>
> that is sweet, thanks, i'll try it out. Appreciate it. :)
>
> Rick
>
> On Wed, Apr 16, 2008 at 9:50 PM, John Krasnay <[EMAIL PROTECTED]> wrote:
>
>> It goes something like this. I've left out a bunch of stuff to do with
>> setting column headings, widths, and styles.
>>
>> public interface ReportColumn extends Serializable {
>> public Object getCellValue(IModel rowModel);
>> }
>>
>> public class ExcelReportGenerator implements ReportGenerator {
>> public void generate(
>> OutputStream outputStream,
>> ReportColumn[] columns,
>> IDataProvider dataProvider) throws IOException {
>>
>> HSSFWorkbook workbook = new HSSFWorkbook();
>> HSSFSheet sheet = workbook.createSheet();
>>
>> Iterator iter = dataProvider.iterator(0, dataProvider.size());
>> while (iter.hasNext()) {
>> Object o = iter.next();
>> IModel rowModel = dataProvider.model(o);
>> row = sheet.createRow(rownum++);
>> for (short i = 0; i < columns.length; i++) {
>> HSSFCell cell = row.createCell(columnNumber,
>> HSSFCell.CELL_TYPE_STRING);
>> Object value = column.getCellValue(rowModel);
>> cell.setCellValue(new
>> HSSFRichTextString(value.toString()));
>> }
>> }
>>
>> workbook.write(outputStream);
>> }
>> }
>>
>>
>> We then use a Link with code like this in its onClick method:
>>
>> public void onClick() {
>> final ReportGenerator generator = getReportGenerator();
>>
>> IResourceStream resourceStream =
>> new AbstractResourceStreamWriter() {
>> public void write(OutputStream output) {
>> try {
>> generator.generate(output, columns, dataProvider);
>> } catch (IOException e) {
>> throw new RuntimeException(e);
>> }
>> }
>> public String getContentType() {
>> return generator.getContentType();
>> }
>>
>> };
>>
>> getRequestCycle().setRequestTarget(
>> new ResourceStreamRequestTarget(resourceStream)
>> .setFileName(getFileName()));
>> }
>>
>>
>> jk
>>
>> On Wed, Apr 16, 2008 at 09:25:41PM -0400, Ricky wrote:
>> > Can someone post some code on this ? (only rough sketch ... nothing
>> > elaborate really.
>> >
>> > Thanks in advance.
>> > Rick
>> >
>> > On Wed, Apr 16, 2008 at 8:54 PM, John Krasnay <[EMAIL PROTECTED]> wrote:
>> >
>> > > Hi RG,
>> > >
>> > > You probably want to look at how DataTable in wicket-extensions
>> works.
>> > > The idea is you set up an array of column objects, each of which
>> knows
>> > > how to display the data in a particular column, and a data provider,
>> > > which provides an iterator over the objects represent your rows. The
>> > > DataTable puts these two together and renders an HTML table.
>> > >
>> > > You can tackle your PDF problem in a similar way. Create a different
>> > > column abstraction that writes to the iText API, then create a
>> component
>> > > analagous to DataTable but that writes the PDF out to a stream.
>> > > Internally, this DataTable-equivalent would create the iText
>> document,
>> > > iterate over the rows returned by the data provider, and for each row
>> > > iterate over the columns, asking each column to render its particular
>> > > cell.
>> > >
>> > > We use this approach for generating spreadsheets (using POI instead
>> of
>> > > iText, of course) and it works like a charm.
>> > >
>> > > jk
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
> --
>
> Regards
> Vyas, Anirudh
> || ॐ ||
>
>
--
View this message in context:
http://www.nabble.com/Wicket-%2B-iText---tp16733269p18141986.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]