7 Replies Latest reply on Mar 24, 2009 2:45 PM by rulinsun

    Issues to use menuitem to export files

      I have problem to user menuitems to export files:
      the menubar was codes as following:

      <rich:toolBar style="width:980px;">
       <rich:dropDownMenu style="text-decoration:underline;">
       <f:facet name="label">
       <h:panelGroup>
       <h:outputText value="Display"/>
       </h:panelGroup>
       </f:facet>
       <rich:menuItem value="Summary"
       action="#{controller.showSummary}"
       >
       </rich:menuItem>
       <rich:menuItem value="Split"
       action="#{controller.showSplit}"
       >
       </rich:menuItem>
       ...
       </rich:dropDownMenu>
       <rich:dropDownMenu style="text-decoration:underline;">
       <f:facet name="label">
       <h:panelGroup>
       <h:outputText value="Export"/>
       </h:panelGroup>
       </f:facet>
       <rich:menuItem value="Summary"
       action="#{controller.exportSummary}"
       >
       </rich:menuItem>
       <rich:menuItem value="Split"
       action="#{controller.exportSplit}"
       >
       </rich:menuItem>
       ...
       </rich:dropDownMenu>
      </rich:toolBar>

      and backBean Controller.java

      private void exportFile(String fileName, String content){
       FacesContext fc = FacesContext.getCurrentInstance();
       HttpServletResponse response = (HttpServletResponse)
       fc.getExternalContext().getResponse();
       String fileFullName = fileName + ".txt";
       response.setHeader("Content-disposition",
       "attachment; filename=" + fileFullName);
       response.setContentType(MBSEConstants.TEXT_TYPE);
      
       try{
       PrintWriter pw = response.getWriter();
      
       pw.write(content);
       pw.flush();
       pw.close();
       fc.responseComplete();
       }
       catch(IOException e){
       logger.error(StackUtil.getStackTrace(e));
       }
       }
      
       public String exportSummary(){
       String inFile="summary";
       exportFile(inFile, readFile(inFile));
       return "success";
       }

      ...

      It works fine, when you select any "Export" menuitem for the first time, then when you select another menuitem, the "exportXXX" functions of the early selected menuitems are also executed, the actually exported content is always of the result of the first menuitem ("Summary"). And now when user selects the menuitem in the "Display" dropdown, all the exportXXX functions will also been called.

      I am not sure if this is same problem with early post about menuitem being executed twice.
      http://www.jboss.org/index.html?module=bb&op=viewtopic&t=150976,
      I tried all suggestions in that post, nothing worked. It seems like it relates to the "Export" which actually stays in same view, and displays a popup to allow user to save the file.


      Anyone has suggestions?

      Thanks!

      Rulin


        • 1. Re: Issues to use menuitem to export files
          nbelaevski

          Hello Rulin,

          That's not the problem described by Aish. What is RF version?

          • 2. Re: Issues to use menuitem to export files

            Thanks for looking to problem.

            We use 3.2.0, we can't migrate to latest version because the manager doesn't want current stable code having big change.

            • 3. Re: Issues to use menuitem to export files
              nbelaevski

              You can try to backport patch for this to 3.2.0. As far as I remember, the problem was somewhere in form.js file, however I'm not sure.

              • 4. Re: Issues to use menuitem to export files

                Thanks for the suggestion!

                I tried replace form.js (both in ajax/richfaces packages), no help. But when I put rachfaces 3.3.0 jars, this problem was gone. Unfortunately, I have some other problems to use 3.3.0,
                1) All the headers of the scrollableDataTable are disappeared. I guess this is because we put a <h:panelGrid> inside the <f:facet name="header"> to wrap the header labels so that we can display multiple-row headers.
                2) Our users like the multiple selections and frozenColumn feature of the scrollableDataTable, but they don't like the actually scrolling, which cause the table unstable, so we develop a workaround of pagenation for scrollableDataTable by sending sublist of data with our TableController, and called reloadData() method in scrollabledatatable.js on client (reRender scrollableDataTable would cause the headers flashing), this doesn't work anymore in 3.3.0., the data will not replaced.

                We tried but couldn't find the solutions for both problems, so we decide continue to use 3.2.0. Can you give me another guess which js files might fix this menuitem issue?

                Rulin

                • 5. Re: Issues to use menuitem to export files
                  nbelaevski

                  You can try menu scripts.

                  • 6. Re: Issues to use menuitem to export files

                    No good. It will try more.

                    Thanks anyway!

                    Rulin

                    • 7. Re: Issues to use menuitem to export files

                      We decided to migrate into 3.3.0 to resolve this issue. I also found solutions for multi-row headers and pagenation without header flashing for SDT from other posts.

                      Thanks!

                      Rulin