At the end of the last post in our OFBiz tutorial series we have completed the final version of a simple product list screen completely based on OFBiz widgets.

The end result is this:

The final result

Our next goal, the subject of this post, is to provide a CSV (Comma Separated Value) export of the same list of products; we will do this by reusing as much as possible the artifacts already implemented for the html screen.

A CSV file is a widely used simple format for the exchange of data between different software systems; for example, Microsoft Excel can easily import a CSV file into a spreadsheet. From a technical point of view a CSV file is a plain text file where each line represents a row from a list of homogeneous data, and the fields are separated by the comma character.
CSV exports are supported out of the box by the OFBiz widgets.
In this excercise we will:

  1. add to the product list screen a link that will generate the CSV export
  2. add to the controller.xml file the request and view entries for the new CSV export screen
  3. implement the new screen definition for the CSV export screen; the screen will reuse the same form used by html screen

Adding a link element

We will add a link from the product list screen to invoke the product CSV export screen. The definition of a link element in a screen is easy:

the “container” element is not mandatory but we have used it in order to create an invisible region of the screen for the links (we will add a new link in our next post, for PDF exports)

  • the link element is defined in the same way we have defined the link field in the product list form in our last post

Controller entries for a CSV export screen…

The entries are very similar to the ones we have implemented in a previous post for the product list screen. There are just a couple of things to notice:

  • the request-map uri must match with the target of the link element in the screen (“ProductListExport”)
  • in the view-map, the type is now “screencsv” (instead of “screen”) because we have to invoke the “csv screen renderer”
  • in the view-map we have also set the content-type to “text/csv” as useful metadata information for the browser

Screen definition for CSV export screens

There isn’t anything special in a screen definition for a CSV export; the screen is defined in the same way of a normal screen, except for a couple of details:

The screen definition is mostly identical to the “product list screen”

  • in particular, the entity-condition element is the same and it is used to select the list of products for the export
  • the form that is included is the same of the “product list screen”: we will not have to re-implement it because the widget renderer will take care of rendering it into the proper output (CSV or html)
  • the “set” field operation, where we set “viewSize” to “10000”, is an easy way to “disable” pagination; we actually define the top limit of our product export to 10000 records here, but of course we can use a different value

Conclusion

The exercise is complete and we can test the product export by clicking the “CSV Export” link (there is no need to restart OFBiz).

Implementing the CSV export ended up being a trivial task because, thanks to the OFBiz widgets, we have reused most of the work we did for the html screen.

In the next tutorial post we will perform similar steps to implement the PDF version of the same screen.

– Jacopo

 


DATE: Feb 11, 2010
AUTHOR: Jacopo Cappellato
OFBiz Tutorials, OFBiz Ecommerce, OFBiz Development, OFBiz Tutorial, OFBiz CSV, Product CSV export, Adding a link element, OFBiz, Jacopo Cappellato