Skip to main content

Exporting CSV using JSF 2.1

Posted by mriem on November 7, 2011 at 10:02 AM PST

If you want to export CSV using JSF read on. The following steps tell you how easy it is.

  1. Install the JSF CSV JAR file.
  2. Create a JSF page with the proper render kit id and content type
  3. Demo it!

Install the JSF CSV JAR file

If you are non-Maven user you will need to download the JAR file manually from
http://www.manorrock.com/repo/com/manorrock/jsf/com-manorrock-jsf-csv/.
And copy it into your WEB-INF/lib directory.
 

If you are a Maven user use the following dependency:

<dependency>
  <groupId>com.manorrock.jsf</groupId>
  <artifactId>com-manorrock-jsf-csv</artifactId>
  <version>2.0.1</version>
</dependency>

Create the JSF page with the proper render kit id and content type
 

 <f:view 
    renderKitId="CSV"
    contentType="text/csv"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
    <h:dataTable var="item" value="#{csvBean.table}">
        <h:column>
            <f:facet name="header"><h:outputText value="one"/></f:facet>
            <h:outputText value="#{item.columnOne}"/>
        </h:column>
        <h:column>
            <f:facet name="header"><h:outputText value="two"/></f:facet>
            <h:outputText value="#{item.columnTwo}"/>
        </h:column>
    </h:dataTable>
</f:view>

Demo it!
 

And head on over to http://www.manorrock.com/demo/jsf/csv/ to see it in action!
 

Comments

I opened up the source and see that it has a generic ...

I opened up the source and see that it has a generic license. I think you would have a better chance at adoption from a corporate standpoint if you provided an approved open source license. As an example, our company would accept Apache 2, and MIT, but would not accept GPL v2, or v3.

Interesting project, and demo. What is the license for the ...

Interesting project, and demo. What is the license for the software?