Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsfViewFactory.viewAlreadySet need to check for valid viewId before call equals [SWF-1501] #687

Open
spring-operator opened this issue Nov 26, 2011 · 4 comments
Assignees
Labels
in: core in: integration status: waiting-for-feedback We need additional information before we can continue type: bug

Comments

@spring-operator
Copy link
Contributor

Noel Hernandez opened SWF-1501 and commented

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;
        } 
    }
}

Affects: 2.3.0

@spring-operator
Copy link
Contributor Author

Rossen Stoyanchev commented

Added code formatting. In the future please use code markup especially for lengthy code samples as the ones above!

@spring-operator
Copy link
Contributor Author

Rossen Stoyanchev commented

I've created an issue project from the code above. However, I'm not able to reproduce the NullPointerException. Instead the page loads okay although the dynamic image doesn't show anything. Could you take a look and confirm what's missing? Feel free to fork the project, make changes, and submit a pull request if it's easier.

One thing I've changed is the expression is evaluated in an on-render section of the view state rather than in the view since the Tomcat EL implementation doesn't allow invoking methods. That could be making a difference but either it's still relevant to the issue.

@spring-operator
Copy link
Contributor Author

Noel Hernandez commented

Thank you for the code formatting Rossen.
I don't know if its relevant but I'm using the JBoss EL Implementation, just to be able to invoke methods.
I will download the issue project and I will try to reproduce the issue.

@spring-operator
Copy link
Contributor Author

Rossen Stoyanchev commented

That would be great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core in: integration status: waiting-for-feedback We need additional information before we can continue type: bug
Projects
None yet
Development

No branches or pull requests

2 participants