-
1. Re: Exporting to CSV in SEAM
jimk1723 Feb 27, 2008 6:40 PM (in response to felixk2)Can you add a servlet mapping in your web.xml?
<servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>yourfile.csv</url-pattern> </servlet-mapping>
Where your JSF view is
yourfile.xhtml
.If you need to change the mime type for that extension, look at server/default/deploy/jboss-web.deployer/conf/web.xml; all of th default mime-types are in there.
-
2. Re: Exporting to CSV in SEAM
srini.ragu Feb 27, 2008 6:52 PM (in response to felixk2)You may need to set the 'Content-Disposition' header field with value "inline;filename=hello.csv"
Or have a separate view with url mapped as mentioned above.
-
3. Re: Exporting to CSV in SEAM
felixk2 Feb 27, 2008 6:55 PM (in response to felixk2)Thank you. Your suggestions worked perfectly. One more thing:
Any idea how I can stick a newline into my view? When I try
\n
it puts the literal text into my output.Thanks,
Felix -
4. Re: Exporting to CSV in SEAM
alteskind Mar 12, 2008 9:59 AM (in response to felixk2)Hi! I have the following view:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a="http://richfaces.org/a4j"> <f:view contentType="text/csv"> 12, 323, 43, 76, 32, 62, 73, 38 </f:view> </ui:composition>
Where do I have to set the Content-Disposition header field?
Thanks a lot!
-
5. Re: Exporting to CSV in SEAM
jeffchiu Jun 5, 2008 9:20 PM (in response to felixk2)I know this issue is old but in case anyone stumbles across this page, here's a way to send the HTTP header from JSF. First, create a method in the action to set the header on the response:
public void httpHeadersForCSV() { HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setHeader("Content-disposition", "attachment;filename=data.csv"); }
Then, to call it from JSF pages, I added the following entry in pages.xml. The action gets called before the page is rendered, according to the seam docs.
<page view-id="/generate_csv.xhtml" action="#{action.httpHeadersForCSV}"/>
Not sure if this is the best way to do it, but it is fairly clean and works.