Results 1 to 4 of 4

Thread: Excel data binding

  1. #1
    Join Date
    Oct 2004
    Location
    Belgium
    Posts
    27

    Default Excel data binding

    Probably a trivial question.

    If a user wants to upload a file in a web interface he can easily use Spring's MultiPart support for it. But does Spring support automatic databinding for file types like Excel ? Maybe something like registering a custom editor that populates a bean holding a reference to some Excel value object (cfr. poi).
    I did notice Spring supports Excel as an integrated view technology via AbstractExcelView, but 1) I'm not sure if I should use this as a value object and 2) I don't immediately see how a Controller can set the url on an AbstractExcelView (wich would populate the poi workbook).

    The only way I see is using POI directly in my Controller.

    But maybe I'm completely confused, and gave part of the answer without realizing. In that case put me on the right track :wink:

    Regards,
    M

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    But does Spring support automatic databinding for file types like Excel ?
    No, Spring does not support this. I think requirements for something like this will vary a lot (to what do you want to bind, what layout, etcetera), to create an appropriate abstraction for this.

    Of course you can implement this yourself.
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Remember by the way that MVC states that controller should just create or update a model (database, filesystem, etcetera), and views should render responses to clients. Of course this isn't the golden rule you'll have to stick to forever, but think twice before you go and create a view in your controller.
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  4. #4
    Join Date
    Oct 2004
    Location
    Belgium
    Posts
    27

    Default

    Hi Alef,

    actually I thought only in terms of abstracting the HSSFWorkbook construction, similar to AbstractExcelView.getTemplateSource(String), not specifying any layout at all.

    Implementation I chose was to create a class AbstractExcelHandler that implements an interface FileHandler with one method :
    void handleFile(InputStream inputStream) throws Exception;
    For any specific type of Excel-file a custom class should extend AbstractExcelHandler and be configured as a spring bean.
    The Controller doesn't differ that much from the FileUploadController example (spring-reference, 12.8 ), except having a FileHandler instance that gets the custom class injected and it also registers a custom PropertyEditor that populates a MultipartFile instance so the metadata of the uploaded file is accessible.

    I think this is the basic approach Spring encourages, although I maybe shouldn't have restricted the file handling to an InputStream.
    I just wondered if it would be a good thing if Spring offers more abstraction for Excel (or PDF for that matter) then just a view.
    But then again, I admit I have still much to learn :wink:

    Regards,
    M

Similar Threads

  1. Replies: 1
    Last Post: Jun 24th, 2007, 10:58 AM
  2. Persistent Data Objects and Data Binding
    By Karsten Schmid in forum Architecture
    Replies: 0
    Last Post: Oct 19th, 2005, 04:56 AM
  3. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  4. Question on data binding
    By TRiNiTy in forum Swing
    Replies: 10
    Last Post: Jan 25th, 2005, 07:41 PM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •