CSV Processor for ADF Applications

8-549x250.png

One of the usual requirements during an ADF development is importing / exporting database information from / to a CSV file

Download sample application link.

This solution makes use of a simple and generic code using any iterator (DCIteratorBinding) configured in the view to extract / import information regardless of the number and names of the columns in the database table on which iterates.

The following sample shows configuration:

  • Upload file is enabled. This configuration is achieved by configuring and enabling Trinidad parameters in web.xml file and set usesUpload attribute in af:form tag

     

    2
    web.xml configuration for Trinidad Upload Files

     

    3
    Enable usesUpload in af:form

     

  • Task Flow contains a Manage Bean (CSVProcessor) responsible for managing files and mechanisms of CSV import / export:
    • It has a variable injected and configurable to set the name of DCIteratorBinding.

       

      4
      DCIteratorName injection in CSVProcess bean

       

    • The load method generates an object file CSVFile type that will be used later to import. Uses oracle.adf.model.adapter.dataformat.CSVHandler for reading and writing the data structure you want. In this case a Map <String,String>

       

      Loadfile code fragment
      Load file using CSVHandler API of ADF

       

    • The export method is used by af:fileDownloadActionListener. Generates a CSV file in the following format:
      • The first row corresponds to the name of the columns defined in the table.
      • The other rows contain the information separated by a special character. In the example "|".

       

      7
        Fragment of code that exports to CSV using DCIteratorBinding

       

    • The import method removes previous data and inserts new rows from the file. CSV file contains in the first row exactly the names of the columns of the correspond table that is being updated through DCIteratorBinding and committed into database.

       

      9
        Import CSV file into a ADF Table / Database using DCIteratorBinding

       

  • The UI lets you to see how API works. Load the file via the inputFile, export the table and import the data through the file.

     

    8
      Sample UI interface

     

The sample is only a helpful API for CSV file processing. Doesn't include error handling or unexpected behavior.

Furthermore, the example uses its own schema and database table called Samples which is easily reproducible in Oracle XE database using JDeveloper.

Subscribe to email updates

Recent Posts