WARNING: #{Generate.viewReportPDF}: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'Generate' resolved to null [duplicate]

StackOverflow https://stackoverflow.com/questions/9470643

Question

This question already has an answer here:

I am really new to JSF but here is my problem :

WARNING: #{Generate.viewReportPDF}: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'Generate' resolved to null

I searched and try a lot of things but it didn't work so I am asking for your help :

Here is my Generate.java in package com.test :

package com.test;

import javax.faces.context.FacesContext;
import javax.inject.Scope;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.TransformerException;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import javax.faces.bean.ManagedBean;

@ManagedBean
public class Generate {
    ...

    public void viewReportPDF () throws IOException {
     ...   
    }

}

Here is my web.xml (in WEB-INF)

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/init.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Here my faces-config.xml (in WEB-INF) :

<managed-bean>
        <managed-bean-name>Generate</managed-bean-name>
        <managed-bean-class>
            com.test.Generate
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

here my init.jsp :

<jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:jsp="http://java.sun.com/JSP/Page">
        <jsp:directive.page contentType="text/html;charset=UTF-8"
            pageEncoding="UTF-8" />
        <f:view>
            <html>
            <head>
            <title>Test iReport With JSF</title>
            </head>
            <body style="background-color: #fff4db">
            <h:form id="reportForm" target="report">
                <h:commandButton id="pdfButton" value="Visualiser PDF"
                    styleClass="buttonStyle" action="#{Generate.viewReportPDF}" />

            </h:form>
            </body>
            </html>
        </f:view>
    </jsp:root>

And when I run I have this error :

WARNING: #{Generate.viewReportPDF}: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'Generate' resolved to null

Was it helpful?

Solution

The Java naming conventions state that instance variable names starts with lowercase. You need to use #{generate.viewReportPDF} instead of #{Generate.viewReportPDF}.

If you really insist in using a capitalized instance variable name (which is bad), then you can always override it in the @ManagedBean annotation:

@ManagedBean(name="Generate")
@SessionScoped
public class Generate {

Note that I added the @SessionScoped annotation, you forgot that. You should also remove that superfluous and old fashioned managed bean configuration in faces-config.xml which would only clash with the annotations and override them. I would also recommend using Facelets instead of the ancient JSPX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top