DisplayTag

TableDecorator created with 1.0 doesn't work properly with 1.1. Properties defined only it decorator

Details

  • Type: Bug Bug
  • Status: Reopened Reopened
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1
  • Fix Version/s: 1.3
  • Component/s: None
  • Labels:
    None
  • Application server:
    TC 4.1.31

Description

I made a TableDecorator to use displaytags on a list of Object[], where I defined all properties in the customized TableDecorator.
It seem to work fine when displayin on web, with sorting and everything, but when trying to export to Excel, it throws an exception for propertyNotFound.

the class :

package no.song.polka.web.decorators;

import org.displaytag.decorator.TableDecorator;
import org.apache.log4j.Logger;
import no.song.polka.business.*;


/**
 * Created by IntelliJ IDEA.
 * User: Frode Halvorsen
 * Date: 12.feb.2005
 * Time: 02:05:18
 * To change this template use File | Settings | File Templates.
 */
public class ResponsibleProviders extends TableDecorator {
    private final Logger log = Logger.getLogger(getClass().getName() + "(" + System.identityHashCode(this) + ")");

    private Object[] getObjects() {
        return (Object[]) getCurrentRowObject();
        // return (Object[]) ((ArrayList) getDecoratedObject()).get(getListIndex());
    }

    public String getFromNumber() {
        return ((String) getObjects()[0]).split("-")[0];
    }

    public String getSeries() {
        String series = (String) getObjects()[0];
        String numbers[] = series.split("-");
        return numbers[0].equals(numbers[1]) ? numbers[0] : series;
    }

    public String getToNumber() {
        String numbers[] = ((String) getObjects()[0]).split("-");

        return numbers[0].equals(numbers[1]) ? " " : numbers[1];
    }

    public String getDsp() {
        return "" + (Destination) getObjects()[1];
    }

    public String getOdsp() {
        return "" + (Destination) getObjects()[2];
    }


}


....
the usage :


<display:table name="result" htmlId="searchResult" id="row" class="polka" export="true" requestURI="p_17.spr?reuse=true" decorator="no.song.polka.web.decorators.ResponsibleProviders">
    <display:setProperty name="basic.msg.empty_list_row" value='<tr class="empty"><td colspan="{0}">Søk på nytt.</td></tr>'/>
    <display:setProperty name="export.excel.filename" value="providers.xls"/>
    <!--display:column property="fromNumber" title="Telefonnummer" /-->
    <!--display:column property="toNumber" title="(serie-slutt)" /-->
    <display:column property="series" title="Telefonnummer" sortable="true"/>
    <display:column property="dsp" title="Nåværende Tilbyder" />
    <display:column property="odsp" title="Opprinnelig tilbyder" />
</display:table>

....
the stacktrace when clicking 'excel' :

Exception: [.LookupUtil] Error looking up property "series" in object type "[Ljava.lang.Object;". Cause: Unknown property 'series'
at org.displaytag.util.LookupUtil.getBeanProperty(LookupUtil.java:141)
at org.displaytag.model.Column.getValue(Column.java:124)
at org.displaytag.export.BaseExportView.doExport(BaseExportView.java:265)
at org.displaytag.tags.TableTag.writeExport(TableTag.java:1469)
at org.displaytag.tags.TableTag.doExport(TableTag.java:1356)
at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1227)
at org.apache.jsp.p_17_jsp._jspService(p_17_jsp.java:437)
.
.
.
.
  1. DISPL-298-displaytag-examples-patch.txt
    15/Mar/06 8:18 PM
    2 kB
    Jorge L. Barroso
  2. DISPL-298-displaytag-export-poi-patch.txt
    15/Mar/06 8:18 PM
    1 kB
    Jorge L. Barroso
  3. DISPL-298-displaytag-patch.txt
    15/Mar/06 8:18 PM
    26 kB
    Jorge L. Barroso
  4. DISPL-298-doc-patch.txt
    28/May/06 3:03 PM
    12 kB
    Jorge L. Barroso
  5. DISPL-298-ExportLinksTest-patch.txt
    15/Mar/06 8:32 PM
    0.8 kB
    Jorge L. Barroso
  6. DISPL-298-NoContextTest-patch.txt
    15/Mar/06 8:32 PM
    0.8 kB
    Jorge L. Barroso
  7. DISPL-298-tests-patch.txt
    28/May/06 3:01 PM
    8 kB
    Jorge L. Barroso

Issue Links

Activity

Hide
Jorge L. Barroso added a comment -
Try adding this config prop to your jsp:
    <display:setProperty name="export.excel.decorator" value="no.song.polka.web.decorators.ResponsibleProviders" />

The Excel, PDF, and RTF exporters look for their own decorators as usually their decorators do Hssf or iText work, whereas the the HTML decorator does html-related work.
Show
Jorge L. Barroso added a comment - Try adding this config prop to your jsp:     <display:setProperty name="export.excel.decorator" value="no.song.polka.web.decorators.ResponsibleProviders" /> The Excel, PDF, and RTF exporters look for their own decorators as usually their decorators do Hssf or iText work, whereas the the HTML decorator does html-related work.
Hide
Frode Halvorsen added a comment -
This worked, but not the same as in 1.0, and it was not mentioned in the migration-guide. It should probably have been mentioned there...

Show
Frode Halvorsen added a comment - This worked, but not the same as in 1.0, and it was not mentioned in the migration-guide. It should probably have been mentioned there...
Hide
Jorge L. Barroso added a comment -
You're right, it should be documented. Unfortunately, I didn't have a chance to contribute documentation for the new exports before the release, but it's coming soon.
Show
Jorge L. Barroso added a comment - You're right, it should be documented. Unfortunately, I didn't have a chance to contribute documentation for the new exports before the release, but it's coming soon.
Hide
fabrizio giustina added a comment -
let's keep this open. We have to update docs or restore the previous behavior
Show
fabrizio giustina added a comment - let's keep this open. We have to update docs or restore the previous behavior
Hide
Jorge L. Barroso added a comment -
Fabrizio, what's your take on this solution, a combination of the old and new behavior?
1. If only one decorator is configured, in the table property, then assume it's meant to be used with all media.
2a. If media-specific decorators are configured, assume the one configured in the table prop is for html, and use the others with the appropriate exporters.
2b. Alternate to 2a, if media-specfic decorators are configured, ignore decorator configured in table decorator prop. Would force user to explicity configure html decorator if other media decorators are configured, but it could be considered more consistent.

I vote for 1. and 2a.
Show
Jorge L. Barroso added a comment - Fabrizio, what's your take on this solution, a combination of the old and new behavior? 1. If only one decorator is configured, in the table property, then assume it's meant to be used with all media. 2a. If media-specific decorators are configured, assume the one configured in the table prop is for html, and use the others with the appropriate exporters. 2b. Alternate to 2a, if media-specfic decorators are configured, ignore decorator configured in table decorator prop. Would force user to explicity configure html decorator if other media decorators are configured, but it could be considered more consistent. I vote for 1. and 2a.
Hide
Jorge L. Barroso added a comment -
----- related problem ---------------

I am getting problems while exporting the values to PDF/Excel by using display tag
all values are getting in pdf/excel expcept the Column Totals

How Can I get the Column Totals in PDF/EXCEL

Please help me

Thanks in advanvce

Krishna Mangamuri

----- evaluation ---------------

The problem is twofold:

1. The new total decorators don't implement interfaces expected
    by the excel and pdf exporters, namely,
    org.displaytag.decorator.hssf.DecoratesHssf for excel and
    org.displaytag.render.ItextDecorator

    Implementing these interfaces should be required only if the
    decorator needs to do hssf or itext work. In general, they
    should become optional.

    As a workaround, you'll need to extend the total decorator you're using,
    (org.displaytag.decorator.MultilevelTotalTableDecorator or
    TotalTableDecorator)
    so that they implement these interfaces.

2. You'll also need to explicitly configure you're new excel and pdf
    decorators, like so.
    <display:setProperty name="export.excel.decorator" value="name.of.your.excel.decorator" />
    <display:setProperty name="export.pdf.decorator" value="name.of.your.pdf.decorator" />

Show
Jorge L. Barroso added a comment - ----- related problem --------------- I am getting problems while exporting the values to PDF/Excel by using display tag all values are getting in pdf/excel expcept the Column Totals How Can I get the Column Totals in PDF/EXCEL Please help me Thanks in advanvce Krishna Mangamuri ----- evaluation --------------- The problem is twofold: 1. The new total decorators don't implement interfaces expected     by the excel and pdf exporters, namely,     org.displaytag.decorator.hssf.DecoratesHssf for excel and     org.displaytag.render.ItextDecorator     Implementing these interfaces should be required only if the     decorator needs to do hssf or itext work. In general, they     should become optional.     As a workaround, you'll need to extend the total decorator you're using,     (org.displaytag.decorator.MultilevelTotalTableDecorator or     TotalTableDecorator)     so that they implement these interfaces. 2. You'll also need to explicitly configure you're new excel and pdf     decorators, like so.     <display:setProperty name="export.excel.decorator" value="name.of.your.excel.decorator" />     <display:setProperty name="export.pdf.decorator" value="name.of.your.pdf.decorator" />
Hide
Jorge L. Barroso added a comment -
From DISPL-295. Clearly describes the issue.

I am in the process of upgrading to 1.1 from 1.0. Previously, exporting would default the decorator class to the decorator specified in the displaytag:table tag. But after upgrading to 1.1, I must now explicitly set each export type to the same decorator. This seems like a bug as it will not allow a "drop-in" upgrade from 1.0 to 1.1.

Example:

This used to work fine:
<display:table ... decorator="com.whatever.MyDecorator">
   ....
</display:table>

But now I must go into every jsp and change to this:
<display:table ... decorator="com.whatever.MyDecorator">
   <display:setProperty name="export.excel.decorator" value="com.whatever.MyDecorator"/>
   <display:setProperty name="export.csv.decorator" value="com.whatever.MyDecorator"/>
   <display:setProperty name="export.pdf.decorator" value="com.whatever.MyDecorator"/>
   <display:setProperty name="export.xml.decorator" value="com.whatever.MyDecorator"/>
   ....
</display:table>
Show
Jorge L. Barroso added a comment - From DISPL-295. Clearly describes the issue. I am in the process of upgrading to 1.1 from 1.0. Previously, exporting would default the decorator class to the decorator specified in the displaytag:table tag. But after upgrading to 1.1, I must now explicitly set each export type to the same decorator. This seems like a bug as it will not allow a "drop-in" upgrade from 1.0 to 1.1. Example: This used to work fine: <display:table ... decorator="com.whatever.MyDecorator">    .... </display:table> But now I must go into every jsp and change to this: <display:table ... decorator="com.whatever.MyDecorator">    <display:setProperty name="export.excel.decorator" value="com.whatever.MyDecorator"/>    <display:setProperty name="export.csv.decorator" value="com.whatever.MyDecorator"/>    <display:setProperty name="export.pdf.decorator" value="com.whatever.MyDecorator"/>    <display:setProperty name="export.xml.decorator" value="com.whatever.MyDecorator"/>    .... </display:table>
Hide
Jorge L. Barroso added a comment -
Attached are patches that address Frode's issue.

Frode's decorator does not render html, but modifies the model or values
returned. Such non-rendering decorators should not have to implement the Hssf-
and iText- "decorates" interfaces.

This patch applies the following rule.
  The table decorator that should be applied to the table is:
  either the decorator configured in the property "decorator",
  or if none is configured in said property,
  a decorator configured with the "decorator.media.[media type]" property.

This patch deprecates the export decorator property
export.[media type].decorator, replacing it with
decorator.media.[media type]. The reason for this change is that
there are cases where you'd need to configure a table decorator to render html
using this property, as in decorator.media.html=x.y.HtmlTableDecorator

Unit tests are included in the patch. I also created jsp's for unit tests
that required visual inspection. If you want those as well, let me know.
Lastly, if and when this patch is applied, I'll contribute a documentation patch.

-Jorge
  
Show
Jorge L. Barroso added a comment - Attached are patches that address Frode's issue. Frode's decorator does not render html, but modifies the model or values returned. Such non-rendering decorators should not have to implement the Hssf- and iText- "decorates" interfaces. This patch applies the following rule.   The table decorator that should be applied to the table is:   either the decorator configured in the property "decorator",   or if none is configured in said property,   a decorator configured with the "decorator.media.[media type]" property. This patch deprecates the export decorator property export.[media type].decorator, replacing it with decorator.media.[media type]. The reason for this change is that there are cases where you'd need to configure a table decorator to render html using this property, as in decorator.media.html=x.y.HtmlTableDecorator Unit tests are included in the patch. I also created jsp's for unit tests that required visual inspection. If you want those as well, let me know. Lastly, if and when this patch is applied, I'll contribute a documentation patch. -Jorge   
Hide
Jorge L. Barroso added a comment -
These patches update older tests to now expect two additional export links, rtf and wpdf.
Show
Jorge L. Barroso added a comment - These patches update older tests to now expect two additional export links, rtf and wpdf.
Hide
Jorge L. Barroso added a comment -
Fabrizio, let me know if I can help you with this patch. Send details, plz.
Show
Jorge L. Barroso added a comment - Fabrizio, let me know if I can help you with this patch. Send details, plz.
Hide
fabrizio giustina added a comment -
> Fabrizio, let me know if I can help you with this patch. Send details, plz.

thanks Jorge. At the moment I have a few tests failing due to a number of links different from the expected: your patches also increases the number of the expected links but by deleding the displaytag.properties file from src/test/resources you get less links than before... anyway, I'm going to commit the patch as is and we will fix the broken tests later, ok?

Apart from this looks ok, but we need to add at least some basic documentation before closing this issue, could you do that?
Show
fabrizio giustina added a comment - > Fabrizio, let me know if I can help you with this patch. Send details, plz. thanks Jorge. At the moment I have a few tests failing due to a number of links different from the expected: your patches also increases the number of the expected links but by deleding the displaytag.properties file from src/test/resources you get less links than before... anyway, I'm going to commit the patch as is and we will fix the broken tests later, ok? Apart from this looks ok, but we need to add at least some basic documentation before closing this issue, could you do that?
Hide
Jorge L. Barroso added a comment -
DISPL-298-tests-patch.txt updates export unit tests to expect additional exports and includes a unit test to assert the precedence of table decorator configurations.
Show
Jorge L. Barroso added a comment - DISPL-298-tests-patch.txt updates export unit tests to expect additional exports and includes a unit test to assert the precedence of table decorator configurations.
Hide
Jorge L. Barroso added a comment -
DISPL-298-doc-patch.txt documents use of table decorators and exports.
Show
Jorge L. Barroso added a comment - DISPL-298-doc-patch.txt documents use of table decorators and exports.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:

Time Tracking

Estimated:
Not Specified
Original Estimate - Not Specified
Remaining:
Not Specified
Remaining Estimate - Not Specified
Logged:
1d
Time Spent - 1 day