Uploaded image for project: 'Spring Web Flow'
  1. Spring Web Flow
  2. SWF-1501

JsfViewFactory.viewAlreadySet need to check for valid viewId before call equals

    XMLWordPrintable

    Details

      Description

      What steps will reproduce the problem?
      1. Create any dynamic streamed context
      2. Make a reference to the resulting image on page of a Spring Web Flow view-state
      3. The image is show but you get a null pointer exception in

      java.lang.NullPointerException
      at org.springframework.faces.webflow.JsfViewFactory.viewAlreadySet(JsfViewFactory.java:138)
      

      in spring web flow source code 2.3.0

      private boolean viewAlreadySet(FacesContext facesContext, String viewName) {
          if (facesContext.getViewRoot() != null && facesContext.getViewRoot().getViewId().equals(viewName)) {
              // the corner case where a before RESTORE_VIEW PhaseListener has handled setting the UIViewRoot
              return true;
          } else {
              return false;
          }
      }
      

      facesContext.getViewRoot().getViewId() is null because in the primefaces library in DynamicContentStreamer set the viewRoot to an UIViewRoot without ID on this line
      facesContext.setViewRoot(new UIViewRoot());

      private void finalizeResponse(FacesContext facesContext) throws IOException {
          HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
      
          response.setStatus(200);
          response.getOutputStream().flush();
          facesContext.setViewRoot(new UIViewRoot());
          facesContext.responseComplete();
      }
      

      What is the PrimeFaces version?
      2.2.1
      What is the expected output? What do you see instead?
      null pointer exception
      Which JSF implementation with version are you using?(Mojarra or MyFaces)
      Mojarra

      What is the version of your JSF implementation?
      2.0.6
      Which component libraries are you using in addition to PrimeFaces?
      none
      Which application server or servlet container are you using?
      tomcat
      To help PrimeFaces team when working on your issue, please paste a
      reproducible test case below.

      Example;

      Page;

      <p:graphicImage value="#{mainEntityController.createDynamicImage()}" />
      ....
      

      Bean

      public class Bean {
      ....
          public StreamedContent createDynamicImage() { 
              try { 
                  StreamedContent chart;
                  DefaultCategoryDataset dataset = new DefaultCategoryDataset();
      
                  for (int i = 0; i < list.size(); i++) {
                      dataset.addValue((Integer)list.get(i).get("value"), 
                      "serie1", (String)list.get(i).get("description"));
                  }
      
                  SpiderWebPlot plot = new SpiderWebPlot(dataset);
      
                  plot.setStartAngle(90);
                  plot.setInteriorGap(0.30);
                  plot.setMaxValue(10);
                  plot.setOutlineVisible(true);
      
                  plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
      
                  JFreeChart jfreechart = new JFreeChart("", TextTitle.DEFAULT_FONT, plot, false);
      
                  ChartUtilities.applyCurrentTheme(jfreechart);
      
                  File chartFile = new File("test.png");
                  ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 512, 400); 
                  chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");
                  return chart;
      
              } catch (Exception e) { 
                  e.printStackTrace(); 
                  return null;
              } 
          }
      }
      

        Attachments

          Activity

            People

            Assignee:
            rstoya05-aop Rossen Stoyanchev
            Reporter:
            noel0402 Noel Hernandez
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: