myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vinay Konanki" <vinay.tob...@gmail.com>
Subject Re: [Tobago] Blocked UI while Exporting to Excel
Date Mon, 09 Apr 2007 23:21:58 GMT
Hi Michal,

Some Progress from my side, now blank Screen is not coming (earlier in my
exportToExcel() Action at the end i used
context.getCurrentInstance().responseComplete();
mistakenly with out writing response back to browser)

Now After exportToExcel() Action the current page is loading but popup
window ("Open, SaveAs, Cancel") window is not showing this means the
getReport() Action is not triggering, even though the javascript
Tobago.Submit('page:storedReport',false) is executing (i'm getting the alert
stmt in that else condition)

 im using Tobago 1.0.11SnapShot and MyFaces 1.1.6 builds

i can see that doAfterLoadingBrowser() method is triggering as i have some
alerts there.
So how my flow so far is as follows:

--> When i click on link to generate excel its calling exportToExcel()
Action and generating excel Report (i have some print statments inside the
action code which are printing in the log file , So im sure this Action is
running Successfully)

--> After that its showing alert ''Found the Element ID and calling that
storedReport link' (But its not triggering getReport() Action in the
Controller, because i dont see any sop statements which are in getReport()
Action)
(This Shows that its able to find the element but not able to call the
Action method)

--> After 1 sec it showing alert 'Came to else probably everything failed
and returning nothing'.
(I dont know again why this alert coming up)?


Regards,
Vinay


On 4/9/07, Michał 'Gandalf' Stawicki <stawicki@gmail.com> wrote:
>
> Right now I don't see what could be wrong, but:
>
> what versions of myfaces and Tobago do you use? I use it with myFaces
> 1.1.6 and Tobago 1.0.11
>
> Also you should check if doAfterLoadingBrowser is ever called, and
> check if page:storedReport is a correct id...
>
> The white screen would suggest some runtime exception  being thrown or
> the response being all wrong..
>
>             servletResponse.setHeader("Content-Disposition",
> "attachment; filename="+attachmentName);
>
> I believe this should rather be:
>
>             servletResponse.setHeader("Content-Disposition",
> "attachment; filename=\""+attachmentName +"\"");
>
> (you have ommited the '"', perhaps you have them in attachmentName?
>
> Here's my response method:
>
> public String getReport()
>     {
>         fetchReport = false;
>
>         FacesContext context = FacesContext.getCurrentInstance();
>         HttpServletResponse response = ( HttpServletResponse )
> context.getExternalContext().getResponse();
>
>         String fileName = reportName;
>         String filePath = reportPath;
>         int read = 0;
>         byte[] bytes = new byte[1024];
>
>         response.setContentType("application/pdf");
>
>         response.setHeader("Content-Disposition", "attachment;filename=\""
> +
> fileName + "\"");
>
>         FileInputStream fis = null;
>         OutputStream ost = null;
>         try
>         {
>             fis = new FileInputStream(new File(filePath));
>             ost = response.getOutputStream();
>
>             while((read = fis.read(bytes)) != -1)
>             {
>                 ost.write(bytes,0,read);
>             }
>
>             ost.flush();
>             ost.close();
>         }
>         catch (FileNotFoundException ex)
>         {
>             ex.printStackTrace();
>         }
>         catch (IOException ex)
>         {
>             ex.printStackTrace();
>         }
>
>         FacesContext.getCurrentInstance().responseComplete();
>
>         return "";
>     }
>
> Try with this one :)
>
> Hope it helps,
> regards
> michael
>
>
>
> On 09/04/07, Vinay Konanki <vinay.tobago@gmail.com> wrote:
> > Thanks Michal,
> >
> > Modified my jsp and Controller according to your suggestion. its working
> > fine until generating excel stuff and storing in an worksheet (i.e in
> > object). but after that its getting blank screen ('White Screen') Its
> not
> > triggering the getReport Action.
> >
> > Here is my code:
> >
> > in generating Excel Action:
> >
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >  public String exportToExcel() {
> > HSSFWorkbook workbook = createWorkbook(data, context);
> >     setFetchReport(true); // Setting FetchReport to true for rendering
> the
> > link in JavaScript
> > return "";
> > }
> >
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > in getReport Action:
> >
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > public String getReport() {
> > Object response = context.getExternalContext().getResponse();
> >         if (response instanceof HttpServletResponse) {
> >           HttpServletResponse servletResponse = (HttpServletResponse)
> > response;
> >           servletResponse.setContentType("application/vnd.ms-excel");
> >           if (StringUtils.isNotEmpty(attachmentName)) {
> >             servletResponse.setHeader("Content-Disposition",
> "attachment;
> > filename="+attachmentName);
> >           }
> >           if(workbook != null)
> >               workbook.write(servletResponse.getOutputStream());
> >           else
> >               System.out.println("workbook is null ");
> >         } else {
> >           //TODO PortletResponse
> >         }
> > return "";
> > }
> >
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >
> > in my jsp page:
> >
> > java Script as follows
> >
> ___________________________________________________________________________________________________
> >  <tc:cell>
> >                 <tc:panel width="0" height="0">
> >                 <tc:script>
> >                     function doAfterLoadingBrowser()
> >                     {
> >                         if(!Tobago.pageIsComplete)
> >                         {
> >
> > setTimeout('doAfterLoadingBrowser()',50);
> >                         }
> >                         else if(document.getElementById
> ('page:storedReport')
> > != null)
> >                         {
> >                             Tobago.submitAction
> ('page:storedReport',false);
> >                             alert('Found the Element ID and calling that
> > storedReport link');
> >                         }
> >                         else
> >                         {
> >                             alert('Came to else probably everything
> failed
> > and returning nothing');
> >                             return;
> >                         }
> >                     }
> >                     doAfterLoadingBrowserTab();
> >                     <tc:link label="" action="#{excelExport.getReport }"
> >                              id="storedReport"
> >                              transition="false"
> >                              rendered="#{excelExport.fetchReport}">
> >                     </tc:link>
> >                 </tc:script>
> >
> >             </tc:panel>
> >             </tc:cell>
> >
> >
> ___________________________________________________________________________________________________
> > actual link calling action that generate the excel stuff is as follows:
> >
> ___________________________________________________________________________________________________
> > <tc:link label="#{bundle.catalogExport }"
> > actionListener="#{excelExport.exportToExcel}"
> >
> > action="#{excelExport.exportToExcel}" transition="true">
> >                            </tc:link>
> >
> >
> __________________________________________________________________________________________________
> >
> > Is there any thing wrong in my jsp page? for some reason its not calling
> the
> > getReport() Action after genrating excel Sheet.
> >
> > Please let me know if any thing wrong with my code.
> > Thanks for your time.
> >
> > Thanks,
> > Vinay
> >
> >
> > On 4/8/07, Michał 'Gandalf' Stawicki <stawicki@gmail.com > wrote:
> > > OK,
> > >
> > > That function afterLoad - I meant pageIsComplete :)
> > >
> > > here's how i have done it:
> > >
> > > On the page I have following code:
> > >
> > >    <tc:panel width="0" height="0">
> > >         <tc:script>
> > >             function doAfterLoadingReportsBrowserTab()
> > >             {
> > >             if (!Tobago.pageIsComplete)
> > >             {
> > >
> > setTimeout('doAfterLoadingReportsBrowserTab()',
> > 50);
> > >             }
> > >             else
> > if(document.getElementById('overview:reportsBrowserTab:storedReport')
> > > != null)
> > >             {
> > >
> > Tobago.submitAction('overview:reportsBrowserTab:storedReport',
> > false);
> > >             }
> > >             else
> > >             {
> > >             return;
> > >             }
> > >             }
> > >             doAfterLoadingReportsBrowserTab();
> > >
> > >             <tc:link
> > >                 label=""
> > >                 id="storedReport"
> > >                 transition="false"
> > >
> > action="#{reportsBrowserManagedBean.reportsBrowserController.getReport}"
> > >
> > rendered="#{
> reportsBrowserManagedBean.reportsBrowserController.fetchReport}"/>
> > >         </tc:script>
> > > </tc:panel>
> > >
> > > And here is your button:
> > >
> > > <tc:link label="#{bundle.catalogExport}"
> > > actionListener="#{excelExport.exportToExcel}"
> > > action="#{excelExport.exportToExcel}" transition="false">
> > >
> > > You have to change yout excelExport method, so it  only creates a file
> > > and stores it somehow and sets fetchReport to true. You also want to
> > > set transition to true
> > >
> > > So, after clicking your button, the same page reloads, but this time
> > > the link with id storedReports is rendered. The included javascript
> > > checks if it exists - and now it does - so it submits the getReport
> > > action - which sends your file to the browser (as described here:
> > > http://wiki.apache.org/myfaces/Sending_Files) and sets
> > fetchReport to
> > > false for obvious reason.
> > >
> > > Perhaps it is not a clean solution, but I didn't come up with anything
> > better
> > >
> > > regards,
> > > michal
> > >
> > >
> > > On 08/04/07, Vinay Konanki <vinay.tobago@gmail.com> wrote:
> > > > Hi Michal,
> > > >
> > > > Thanks for your reply,
> > > > i have couple of doubts in the solution you provided.
> > > > before that let me explain my case.
> > > >
> > > > I have a link which will generate the excel export of all the
> products,
> > > > According to my current Code my <tc:link> will be like this:
> > > >
> > > > <tc:link label="#{ bundle.catalogExport}"
> > > > actionListener="#{excelExport.exportToExcel}"
> > > >
> > > > action="#{excelExport.exportToExcel}" transition="false">
> > > > NB: for this i'm making transition as false
> > > >
> > > > My questions  are:
> > > > 1) How can we set one action for two events i.e generating excel
> stufff
> > > > (calling Controller) and setting an element on the page(with
> Specific
> > ID).
> > > > 2) Can you provide a sample code snippet so that it will be helpful
> for
> > me
> > > > to get an idea.
> > > > 3) I search for afterLoad method in Tobago but i dont find any
> methods
> > > > similar to that, Can you provide code for the java Script and how we
> > will
> > > > call.
> > > > Please provide me Sample Code Snippet, that will be greatly helpful
> for
> > me.
> > > >
> > > > Awaiting your reply.
> > > >
> > > > Thanks,
> > > > Vinay
> > > >
> > > >
> > > >
> > > > On 4/6/07, Michał 'Gandalf' Stawicki < stawicki@gmail.com> wrote:
> > > > > You can do as follows:
> > > > >
> > > > > use a button with transition - pressing the button would generate
> your
> > > > > excel stuff and couse some invisible element to render on the page
> > > > > (with a specific ID)
> > > > >
> > > > > to the page, add a java script using Tobago.afterLoad (perhaps it
> was
> > > > > called some different way, check...) that checks if the special
> > > > > element was rendered and if so, then it submits action that sends
> > > > > excel stuff to the browser without transition. I have been using
> this
> > > > > method  to submit PDF reports :)
> > > > >
> > > > > regards,
> > > > > michał
> > > > >
> > > > > On 07/04/07, Vinay Konanki < vinay.tobago@gmail.com> wrote:
> > > > > > Hi,
> > > > > > Could any one help me in this regard...
> > > > > > I need to done this module as soon as possible
> > > > > >
> > > > > > Any help will be appreciated.
> > > > > >
> > > > > > Thanks,
> > > > > > Vinay
> > > > > >
> > > > > >
> > > > > > On 4/5/07, Vinay Konanki < vinay.tobago@gmail.com> wrote:
> > > > > > > Hi All,
> > > > > > > I got success in generating excel sheet, Thanks for your
help,
> but
> > > > today i
> > > > > > found a problem with in exporting the excel.
> > > > > > >
> > > > > > > Problem was:
> > > > > > > When i'm trying to export the results to excel as there
are
> more
> > than
> > > > 700
> > > > > > elements to generate, it taking around 5-6 seconds to show
> window
> > "which
> > > > > > contains OpenWith SaveAs Cancel" buttons.
> > > > > > > In the mean while when i click on other links in the
> application
> > its
> > > > > > getting blocked UI (i.e non editable UI with progress bar image)
> for
> > > > > > infinite time.
> > > > > > >
> > > > > > > So how can i make the screen as non editable when it
> generating
> > Excel
> > > > > > sheet. i.e. i want to show to the user that some process is
> going on
> > and
> > > > > > make the screen non editable i.e user can not make any actions
> on
> > the
> > > > > > screen.
> > > > > > >
> > > > > > > Is there any way to make the screen non editable while
other
> > process
> > > > is
> > > > > > going on.
> > > > > > >
> > > > > > > Please help me in this regard.
> > > > > > >
> > > > > > > Any kind of help will be appreciated. I'm running out of
time,
> as
> > my
> > > > > > product release is very soon.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Vinay
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > stawicki@gmail.com
> > > > > http://stawicki.jasliska.pl
> > > > > GG: 3691111
> > > > > JID: stawicki@gmail.com
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > stawicki@gmail.com
> > > http://stawicki.jasliska.pl
> > > GG: 3691111
> > > JID: stawicki@gmail.com
> > >
> >
> >
>
>
> --
> stawicki@gmail.com
> http://stawicki.jasliska.pl
> JID: stawicki@gmail.com
> <!-- Failure is not an option...It comes bundled with the software! -->
>
Mime
View raw message