You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by sreekrbs <sr...@yahoo.com> on 2009/04/28 18:31:10 UTC

Re: Export Data Table to Excel - Strange JSF Lifecycle Behavior?!

Very simple solution. Use a command button with image.

JSF Code
<h:commandButton value="Download"  styleClass="button"
actionListener="#{employeeList.downloadListener}"
image="/images/excel_icon.gif" />

Generated HTML
<input id="employees:j_id13" name="employees:j_id13"
				type="image" src="/testapp/images/excel_icon.gif"
				onclick="if(typeof
window.clearFormHiddenParams_employees=='function'){clearFormHiddenParams_employees('employees');}"
				class="button" />





mjovanov wrote:
> 
> We have a very simple setup for exporting data table content to excel: a
> commandLink invoking an action method that renders content type
> "application/vnd.ms-excel". However we are seeing some really funky
> behavior, specifically whenever actions other than exporting to excel are
> invoked, the exportHtmlTableToExcel action method still gets executed
> during JSF lifecycle, causing the browser to display the Download/Open
> dialog box again! Using the debugger I can see the exportHtmlTableToExcel
> getting invoked even though it should not be. It's as if the JSF state
> somehow got corrupt and/or was not properly reset from the previous cycle
> involving Exporting to Excel. Has anyone seen this before? Any suggestions
> would be greatly appreciated.
> 
> code:
> <h:commandLink action="#{backingBean.exportHtmlTableToExcel}"
> class="linkCaption">
>   <t:graphicImage url="images/icon_excel.gif"
> alt="#{msg.labelExportQueueSummToExcel}" width="21" height="16" />
>   <h:outputText value="#{msg.labelExportToExcel}" />
> </h:commandLink>
> 
> public void exportHtmlTableToExcel() throws IOException {
>     String contentType = "application/vnd.ms-excel";
>     FacesContext fc = FacesContext.getCurrentInstance();
>     String filename = fc.getExternalContext().getUserPrincipal().getName()
> + "-" + System.currentTimeMillis()
>             + ".xls";
>     HttpServletResponse response = (HttpServletResponse)
> fc.getExternalContext().getResponse();
>     response.setHeader("Content-disposition", "attachment; filename=" +
> filename);
>     response.setContentType(contentType);
> 
>     StringBuffer htmlBuffer = new StringBuffer();
>     ...
>     [write data table content to buffer here]
>     ...
>     ...
>     PrintWriter out = response.getWriter();
>     htmlBuffer.append("<HTML>\n");
>     out.print(htmlBuffer);
>     out.close();
>     fc.responseComplete();
> }
> 
> 

-- 
View this message in context: http://www.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p23280575.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Export Data Table to Excel - Strange JSF Lifecycle Behavior?!

Posted by davisoski <da...@gmail.com>.
Hi.

I'm trying to export datatable of ICEfaces wich has grouped columns, no just
simply columns.

Anybody has an idea on how to treat this stuff?

thanks



-- 
View this message in context: http://old.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p32648718.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Export Data Table to Excel - Strange JSF Lifecycle Behavior?!

Posted by sreekrbs <sr...@yahoo.com>.
You're right, the second post is the problem. If you do not have the dire
need for a commandlink (I didn't) I would say use command button.



Cagatay Civici wrote:
> 
> Does it only happen for the second post after you export the excel? Or it
> happens without exporting at all?
> 
> Seems commandLink is decoded and event is queued again.
> 
> On Tue, Apr 28, 2009 at 5:31 PM, sreekrbs <sr...@yahoo.com> wrote:
> 
>>
>> Very simple solution. Use a command button with image.
>>
>> JSF Code
>> <h:commandButton value="Download"  styleClass="button"
>> actionListener="#{employeeList.downloadListener}"
>> image="/images/excel_icon.gif" />
>>
>> Generated HTML
>> <input id="employees:j_id13" name="employees:j_id13"
>>                                type="image"
>> src="/testapp/images/excel_icon.gif"
>>                                onclick="if(typeof
>>
>> window.clearFormHiddenParams_employees=='function'){clearFormHiddenParams_employees('employees');}"
>>                                class="button" />
>>
>>
>>
>>
>>
>> mjovanov wrote:
>> >
>> > We have a very simple setup for exporting data table content to excel:
>> a
>> > commandLink invoking an action method that renders content type
>> > "application/vnd.ms-excel". However we are seeing some really funky
>> > behavior, specifically whenever actions other than exporting to excel
>> are
>> > invoked, the exportHtmlTableToExcel action method still gets executed
>> > during JSF lifecycle, causing the browser to display the Download/Open
>> > dialog box again! Using the debugger I can see the
>> exportHtmlTableToExcel
>> > getting invoked even though it should not be. It's as if the JSF state
>> > somehow got corrupt and/or was not properly reset from the previous
>> cycle
>> > involving Exporting to Excel. Has anyone seen this before? Any
>> suggestions
>> > would be greatly appreciated.
>> >
>> > code:
>> > <h:commandLink action="#{backingBean.exportHtmlTableToExcel}"
>> > class="linkCaption">
>> >   <t:graphicImage url="images/icon_excel.gif"
>> > alt="#{msg.labelExportQueueSummToExcel}" width="21" height="16" />
>> >   <h:outputText value="#{msg.labelExportToExcel}" />
>> > </h:commandLink>
>> >
>> > public void exportHtmlTableToExcel() throws IOException {
>> >     String contentType = "application/vnd.ms-excel";
>> >     FacesContext fc = FacesContext.getCurrentInstance();
>> >     String filename =
>> fc.getExternalContext().getUserPrincipal().getName()
>> > + "-" + System.currentTimeMillis()
>> >             + ".xls";
>> >     HttpServletResponse response = (HttpServletResponse)
>> > fc.getExternalContext().getResponse();
>> >     response.setHeader("Content-disposition", "attachment; filename=" +
>> > filename);
>> >     response.setContentType(contentType);
>> >
>> >     StringBuffer htmlBuffer = new StringBuffer();
>> >     ...
>> >     [write data table content to buffer here]
>> >     ...
>> >     ...
>> >     PrintWriter out = response.getWriter();
>> >     htmlBuffer.append("<HTML>\n");
>> >     out.print(htmlBuffer);
>> >     out.close();
>> >     fc.responseComplete();
>> > }
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p23280575.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p23283598.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Export Data Table to Excel - Strange JSF Lifecycle Behavior?!

Posted by Cagatay Civici <ca...@gmail.com>.
Does it only happen for the second post after you export the excel? Or it
happens without exporting at all?

Seems commandLink is decoded and event is queued again.

On Tue, Apr 28, 2009 at 5:31 PM, sreekrbs <sr...@yahoo.com> wrote:

>
> Very simple solution. Use a command button with image.
>
> JSF Code
> <h:commandButton value="Download"  styleClass="button"
> actionListener="#{employeeList.downloadListener}"
> image="/images/excel_icon.gif" />
>
> Generated HTML
> <input id="employees:j_id13" name="employees:j_id13"
>                                type="image"
> src="/testapp/images/excel_icon.gif"
>                                onclick="if(typeof
>
> window.clearFormHiddenParams_employees=='function'){clearFormHiddenParams_employees('employees');}"
>                                class="button" />
>
>
>
>
>
> mjovanov wrote:
> >
> > We have a very simple setup for exporting data table content to excel: a
> > commandLink invoking an action method that renders content type
> > "application/vnd.ms-excel". However we are seeing some really funky
> > behavior, specifically whenever actions other than exporting to excel are
> > invoked, the exportHtmlTableToExcel action method still gets executed
> > during JSF lifecycle, causing the browser to display the Download/Open
> > dialog box again! Using the debugger I can see the exportHtmlTableToExcel
> > getting invoked even though it should not be. It's as if the JSF state
> > somehow got corrupt and/or was not properly reset from the previous cycle
> > involving Exporting to Excel. Has anyone seen this before? Any
> suggestions
> > would be greatly appreciated.
> >
> > code:
> > <h:commandLink action="#{backingBean.exportHtmlTableToExcel}"
> > class="linkCaption">
> >   <t:graphicImage url="images/icon_excel.gif"
> > alt="#{msg.labelExportQueueSummToExcel}" width="21" height="16" />
> >   <h:outputText value="#{msg.labelExportToExcel}" />
> > </h:commandLink>
> >
> > public void exportHtmlTableToExcel() throws IOException {
> >     String contentType = "application/vnd.ms-excel";
> >     FacesContext fc = FacesContext.getCurrentInstance();
> >     String filename =
> fc.getExternalContext().getUserPrincipal().getName()
> > + "-" + System.currentTimeMillis()
> >             + ".xls";
> >     HttpServletResponse response = (HttpServletResponse)
> > fc.getExternalContext().getResponse();
> >     response.setHeader("Content-disposition", "attachment; filename=" +
> > filename);
> >     response.setContentType(contentType);
> >
> >     StringBuffer htmlBuffer = new StringBuffer();
> >     ...
> >     [write data table content to buffer here]
> >     ...
> >     ...
> >     PrintWriter out = response.getWriter();
> >     htmlBuffer.append("<HTML>\n");
> >     out.print(htmlBuffer);
> >     out.close();
> >     fc.responseComplete();
> > }
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p23280575.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>