Wicket
  1. Wicket
  2. WICKET-4802

Add functionality to be able to export DataTable content

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 6.1.0
    • Fix Version/s: 6.2.0
    • Component/s: wicket-extensions
    • Labels:
      None

      Description

      In Igor's book he describes a way of exporting a data table to CSV. It requires tagging exportable columns with a interface, which allows retrieving of the data for the column by passing it the row model.

      I, and I'm sure many others, have implemented this functionality, and we all have our own CSVExportToolbar, or something similar. The problem is that each export implementation is checking for instances of their own hand-crafted IDataColumn interface. This makes it difficult for people to write libraries that provide columns that will be exportable across the board.

      I propose that we add a standard IDataColumn that can be used to tagging exportable columns, and which every CSVExportToolbar and ExcelExportToolbar etc can check for when determining which columns to use to export.

      Something like:

      /** does not need sort parameter, does not need to extend IColumn */
      public interface IDataColumn<R, T>

      { /** get data for row by passing row model, in imodel format to allow this method to be used for rendering in an abstract implementation. */ IModel<T> getDataModel(IModel<R> rowModel); /** get column header, useful in exporting. same signature as AbstractColumn method */ IModel<String> getDisplayModel(); }

      Then an abstract implementation, where the user only needs to implement getDataModel()

      public abstract class AbstractDataColumn<R, S, T>
      extends AbstractColumn<R, S>
      implements IDataColumn<R, T>
      {
      // normal AbstractColumn constructors.

      protected Component createNewDisplayComponent(String componentId, IModel<T> dataModel)

      { return new Label(componentId, dataModel); }

      @Override
      public void populateItem(Item<ICellPopulator<R>> cellItem, String componentId, IModel<R> rowModel)

      { cellItem.add(createNewDisplayComponent(componentId, getDataModel(rowModel))); }

      }

      1. WICKET-4802.patch
        40 kB
        Jesse Long
      2. WICKET-4802.patch
        3 kB
        Martin Grigorov
      3. WICKET-4802-3.patch
        8 kB
        Jesse Long

        Activity

        Hide
        Jesse Long added a comment -

        There are actually 2 use cases for a standard exportable column type:

        1. Allows libraries to provide columns that can be exported by all Wicket apps.
        2. Allows libraries to provide exporting code that can export columns in all Wicket apps (Think export to Microsoft Excel library).

        I have started implementing this idea here: https://github.com/jesselong/wicket/tree/datatable-export

        Its untested, not nicely formatted, undocumented etc, I'll update more when I have time.

        Show
        Jesse Long added a comment - There are actually 2 use cases for a standard exportable column type: 1. Allows libraries to provide columns that can be exported by all Wicket apps. 2. Allows libraries to provide exporting code that can export columns in all Wicket apps (Think export to Microsoft Excel library). I have started implementing this idea here: https://github.com/jesselong/wicket/tree/datatable-export Its untested, not nicely formatted, undocumented etc, I'll update more when I have time.
        Hide
        Martin Grigorov added a comment -

        Hi Jesse,

        I didn't have time to look at your proposal yet.
        I just want to let you know about another implementation of your idea: https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/wicket-poi-parent, https://github.com/wicketstuff/core/wiki/POI.

        Show
        Martin Grigorov added a comment - Hi Jesse, I didn't have time to look at your proposal yet. I just want to let you know about another implementation of your idea: https://github.com/wicketstuff/core/tree/master/jdk-1.6-parent/wicket-poi-parent , https://github.com/wicketstuff/core/wiki/POI .
        Hide
        Jesse Long added a comment -

        Hi Martin,

        Thanks for the heads up. That project parses the HTML generated by the data table. Its a really ugly approach (no fault of the author). This is the type of thing I hope my proposal will make simple.

        That POI project can implement IDataExporter and get the cell values directly from the column, without HTML markup.

        Additional styling for the output can be provided by the column implementing an interface specific to the output target (Excel) that provides styling configuration that makes sense for that IDataExporter.

        Show
        Jesse Long added a comment - Hi Martin, Thanks for the heads up. That project parses the HTML generated by the data table. Its a really ugly approach (no fault of the author). This is the type of thing I hope my proposal will make simple. That POI project can implement IDataExporter and get the cell values directly from the column, without HTML markup. Additional styling for the output can be provided by the column implementing an interface specific to the output target (Excel) that provides styling configuration that makes sense for that IDataExporter.
        Hide
        Jesse Long added a comment -

        WICKET-4802.patch

        Attached is my proposed patch.

        Note that I have added the ...data.table.export package.

        I have also made PropertyColumn implement IExportableColumn - it is a prime candidate for this. It does not extends AbstractExportableColumn because I'm trying to avoid binary incompatibility.

        I have added the export functionality to the data table example in wicket-examples.

        The reason I created this ticket was that IExportableColumn as I have implemented it is missing. The rest of the changes I have made are just by suggestion and some default implementations. I will be content if only IExportableColumn makes it in. (It does make sense to at least keep the PropertyColumn changes too).

        It should be quite simple to implement Excel etc IDataExporters.

        Show
        Jesse Long added a comment - WICKET-4802 .patch Attached is my proposed patch. Note that I have added the ...data.table.export package. I have also made PropertyColumn implement IExportableColumn - it is a prime candidate for this. It does not extends AbstractExportableColumn because I'm trying to avoid binary incompatibility. I have added the export functionality to the data table example in wicket-examples. The reason I created this ticket was that IExportableColumn as I have implemented it is missing. The rest of the changes I have made are just by suggestion and some default implementations. I will be content if only IExportableColumn makes it in. (It does make sense to at least keep the PropertyColumn changes too). It should be quite simple to implement Excel etc IDataExporters.
        Hide
        Martin Grigorov added a comment -

        All of it looks good to me!
        Will be available with 6.2.0.
        Thanks!

        Show
        Martin Grigorov added a comment - All of it looks good to me! Will be available with 6.2.0. Thanks!
        Hide
        Jesse Long added a comment -

        Thank you Martin.

        Show
        Jesse Long added a comment - Thank you Martin.
        Hide
        Martin Grigorov added a comment -

        There is a small problem with the signature of #getDataModel(). See discussion in dev@: http://markmail.org/message/f533bz3pcpoh6r4e

        Show
        Martin Grigorov added a comment - There is a small problem with the signature of #getDataModel(). See discussion in dev@: http://markmail.org/message/f533bz3pcpoh6r4e
        Hide
        Jesse Long added a comment -

        IExportableColumn does not really need the third type parameter...

        Show
        Jesse Long added a comment - IExportableColumn does not really need the third type parameter...
        Hide
        Martin Grigorov added a comment -

        Jesse Long Is WICKET-4802.patch OK ?

        Show
        Martin Grigorov added a comment - Jesse Long Is WICKET-4802 .patch OK ?
        Hide
        Jesse Long added a comment -

        Yes, just looking at the .patch file it looks great. You may have missing a Javadoc comment about the type parameter... I'll check out wicket 7 and look in more detail to check that everything works... Will update here.

        Show
        Jesse Long added a comment - Yes, just looking at the .patch file it looks great. You may have missing a Javadoc comment about the type parameter... I'll check out wicket 7 and look in more detail to check that everything works... Will update here.
        Hide
        Martin Grigorov added a comment -

        I didn't update the javadoc. I just wanted to know whether the change is what you meant.
        There are other impls of IExportableColumn which need to be updated too.
        I'll wait for your update!

        Show
        Martin Grigorov added a comment - I didn't update the javadoc. I just wanted to know whether the change is what you meant. There are other impls of IExportableColumn which need to be updated too. I'll wait for your update!
        Hide
        Jesse Long added a comment -

        I Martin, I am happy with WICKET-4802-3.patch. Effectively what you did plus the other required changes. wicketstuff-poi will need updating. Do you know if there is a wicket-7 branch there. If so, I will update.

        Show
        Jesse Long added a comment - I Martin, I am happy with WICKET-4802 -3.patch. Effectively what you did plus the other required changes. wicketstuff-poi will need updating. Do you know if there is a wicket-7 branch there. If so, I will update.
        Hide
        Martin Grigorov added a comment -

        Thanks for the patch!

        There is no branch for Wicket 7 in WicketStuff yet.
        I will make a branch for wicket 6.x and use master for 7.x (as in Wicket) this week.

        Show
        Martin Grigorov added a comment - Thanks for the patch! There is no branch for Wicket 7 in WicketStuff yet. I will make a branch for wicket 6.x and use master for 7.x (as in Wicket) this week.
        Hide
        Martin Grigorov added a comment -

        WICKET-4802-3.patch is applied in master branch.

        Show
        Martin Grigorov added a comment - WICKET-4802 -3.patch is applied in master branch.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Jesse Long
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development