1

I 'm new to JSF and creating a sample app using jsf2,tomcat6.0 using eclipse kepler.I 'm getting below exception when i click on ubmit button :

SEVERE: Error Rendering View[/index.xhtml] com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean helloWorldBean.  
The following problems were found:      - Bean or property class com.vigilance.jsf for managed bean helloWorldBean cannot be found.     at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:265)    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)   at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)  at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)   at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:69)   at org.apache.el.parser.AstValue.getValue(AstValue.java:112)    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)     at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)   at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)   at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)   at javax.faces.component.UIOutput.getValue(UIOutput.java:169)   at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)  at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)     at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) .

My web.xml is below :

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>JavaServerFaces</display-name>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>       <!-- Welcome page list -->
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>      <!-- JavaServer Faces Servlet -->
    <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 to URL pattern -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
</web-app>

Managedbean - HelloWorldBean.java:

package com.vigilance.jsf;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="helloWorldBean")
@SessionScoped
public class HelloWorldBean implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private String firstName;

    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}

xhtml files - index.xhtmls

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

    <f:loadBundle basename="resources.application" var="msg" />

    <head>
        <title>
            <h:outputText value="#{msg.welcomeTitle}" />
        </title>
    </head>

    <body>
        <h3>
            <h:outputText value="#{msg.welcomeHeading}" />
        </h3>
        <p>
            <h:outputText value="#{msg.welcomeMessage}" />
        </p>
        <h:form>
            <h:panelGrid columns="2">
                <h:outputLabel for="firstName">
                    First Name *
                </h:outputLabel>
                <h:inputText id="firstName"
                    value="#{helloWorldBean.firstName}">
                </h:inputText>

                <h:outputLabel for="lastName">
                    Last Name *
                </h:outputLabel>
                <h:inputText id="lastName"
                    value="#{helloWorldBean.lastName}">
                </h:inputText>

                <h:commandButton value="Submit" action="hello"></h:commandButton>

            </h:panelGrid>
        </h:form>
    </body>
</html>

hello.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
    <f:loadBundle basename="resources.application" var="msg" />

    <head>
        <title>
            <h:outputText value="#{msg.welcomeTitle}" />
        </title>
    </head>
    <h:body>
        <h3>
            <h:outputText value="#{msg.helloHeading}" />
            &nbsp;#{helloWorldBean.firstName}&nbsp;#{helloWorldBean.lastName}
        </h3>
        <p>
            <h:outputText value="#{msg.helloMessage}" />
        </p>
    </h:body>
</html>
Programmer
  • 455
  • 2
  • 8
  • 25
Priyanka
  • 13
  • 3

1 Answers1

0

The following problems were found: - Bean or property class com.vigilance.jsf for managed bean helloWorldBean cannot be found.

This error message suggests that you've a /WEB-INF/faces-config.xml with the following entry:

<managed-bean>
    <managed-bean-class>com.vigilance.jsf</managed-bean-class>
    <managed-bean-name>helloWorldBean</managed-bean-name>
    <managed-bean-scope>[some scope]</managed-bean-scope>
</managed-bean>

This is wrong in 2 ways:

  1. The <managed-bean-class> must represent the fully qualified class name, not the package name.

  2. The whole <managed-bean> entry is unnecessary if you're already using @ManagedBean. Get rid of the whole entry altogether.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks ! Can't say what went wrong as I 've tried removing entry from faces-config.xml but still got some errors for bean not having default constructor.Cleaned the project and upgraded to tomcat 7 and it worked. – Priyanka Sep 04 '13 at 21:44
  • @BalusC when we are using JSF2 still then we need to use 'faces.config.xml' file? – Programmer Sep 05 '13 at 05:14