Integração JSF 1.2 + SPRING 2.5 + JPA

03/12/2009

1

Pessoal estou tendo problemas com a integração do JSF 1.2 e Spring 2.5 vou postar as classes, configurações

minha classe modelo meu Entity

@Entity
public class Customer {
   
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
   
    private String name;
   
    private String email;
   
    @OneToMany(fetch=FetchType.EAGER,mappedBy="customer", cascade={CascadeType.REMOVE})
    private List<Address> addresses;
   
   // get e set ....

}


@Entity
public class Address {
   
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
   
    private String street;
   
    private String number;
   
    private String city;
   
    @Enumerated(EnumType.STRING)
    private State state;
   
    @Enumerated(EnumType.STRING)
    private Country country;
   
    @ManyToOne(fetch=FetchType.EAGER)
    private Customer customer;

   // get e set ....

}

Minhas Interfaces

public interface CustomerDao {
   
    Integer createCustomer(Customer customer);
   
    void updateCustomer(Customer customer);
   
    void deleteCustomer(Customer customer);
   
    Customer findCustomerById(Integer id);
   
    List<Customer> findAllCustomers();
   
    List<Customer> findCustomersByName(String name);

}

public interface AddressDao {
   
    public Integer addAddress(Address address);
   
    public List<Address> findAddresses(Customer customer);

}


Implemantação das Interfaces nas Classes

***********************************************************

@SuppressWarnings("unchecked")
public class JPAAddressDaoImpl extends JpaDaoSupport implements AddressDao {

    @Override
    public Integer addAddress(Address address) {
        getJpaTemplate().persist(address);
        return address.getId();
    }

    @Override
    public List<Address> findAddresses(Customer customer) {
        return (List<Address>) getJpaTemplate().find("From Address a Where a.customer = ?1",customer);
    }

}

*********************************************************************

@SuppressWarnings("unchecked")
public class JPACustomerDaoImpl extends JpaDaoSupport implements CustomerDao {

    @Override
    public Integer createCustomer(Customer customer) {
       
        getJpaTemplate().persist(customer);
        getJpaTemplate().flush();
       
        return customer.getId();
    }

    @Override
    public void deleteCustomer(Customer customer) {
        getJpaTemplate().remove(customer);

    }

    @Override
    public List<Customer> findAllCustomers() {
        return (List<Customer>) getJpaTemplate().find("FROM Customer c");
    }

    @Override
    public Customer findCustomerById(Integer id) {
        return getJpaTemplate().find(Customer.class, id);
    }

    @Override
    public List<Customer> findCustomersByName(String name) {
        return (List<Customer>) getJpaTemplate().find("FROM Customer c Where c.name LIKE ?1",name);
    }

    @Override
    public void updateCustomer(Customer customer) {
        getJpaTemplate().merge(customer);

    }

}


Minha Inteface de Serviço
******************************

public interface CustomerService {

    Integer createCustomer(Customer customer);
   
    Integer createCustomer(Customer customer, Address address);
   
    void updateCustomer(Customer customer);
   
    void deleteCustomer(Customer customer);
   
    Customer findCustomerById(Integer id);
   
    List<Customer> findAllCustomers();
   
    List<Customer> findCustomersByName(String name);
   
    public Integer addAddress(Address address);
   
    public List<Address> findAddresses(Customer customer);
}



Implementação da Classe
************************************

@Transactional
public class CustomerServiceImpl implements CustomerService {

    private CustomerDao customerDao;
    private AddressDao addressDao;

    public void setCustomerDao(CustomerDao customerDao) {
        this.customerDao = customerDao;
    }

    public void setAddressDao(AddressDao addressDao) {
        this.addressDao = addressDao;
    }

    @Override
    public Integer addAddress(Address address) {
        return addressDao.addAddress(address);
    }

    @Override
    public Integer createCustomer(Customer customer) {
        System.out.println("Nome Service:"+customer.getName());
        System.out.println("EMail Service:"+customer.getEmail());
        return customerDao.createCustomer(customer);
    }

    @Override
    public Integer createCustomer(Customer customer, Address address) {
        Integer id = createCustomer(customer);
        address.setCustomer(customer);
        addAddress(address);
        return id;
    }

    @Override
    public void deleteCustomer(Customer customer) {
        customer = findCustomerById(customer.getId());
    }

    @Override
    public void updateCustomer(Customer customer) {
        customerDao.updateCustomer(customer);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Address> findAddresses(Customer customer) {
        return addressDao.findAddresses(customer);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Customer> findAllCustomers() {
        return customerDao.findAllCustomers();
    }

    @Override
    @Transactional(readOnly = true)
    public Customer findCustomerById(Integer id) {
        return customerDao.findCustomerById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Customer> findCustomersByName(String name) {
        return customerDao.findCustomersByName(name);
    }
}


Segue partes do meu projeto

meu aplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/customer" />
        <property name="username" value="postgres" />
        <property name="password" value="root" />
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="false" />
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
            </bean>
        </property>
    </bean>
   
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <tx:annotation-driven mode="proxy" />

    <context:annotation-config />

    <bean id="customerDao" class="br.com.jm.spring.customer.db.dao.JPACustomerDaoImpl">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="addressDao" class="br.com.jm.spring.customer.db.dao.JPAAddressDaoImpl">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="customerService"
        class="br.com.jm.spring.customer.db.service.CustomerServiceImpl">
        <property name="customerDao" ref="customerDao" />
        <property name="addressDao" ref="addressDao" />
    </bean>

</beans>


Web.xml

<?xml version="1.0"?>
<web-app version="2.5" 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_2_5.xsd">
    <display-name>CustomerWEB</display-name>

    <!-- Configuracao do Spring -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/beans.xml</param-value>
    </context-param>

    <!-- Listener do Spring -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Plugging the "Blue Sky" skin into the project -->
    <context-param>
        <param-name>org.richfaces.SKIN</param-name>
        <param-value>blueSky</param-value>
    </context-param>
    <!-- Making the RichFaces skin spread to standard HTML controls -->
    <context-param>
        <param-name>org.richfaces.CONTROL_SKINNING</param-name>
        <param-value>disable</param-value>
    </context-param>

    <!-- Defining and mapping the RichFaces filter -->
    <filter>
        <display-name>RichFaces Filter</display-name>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <!-- 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>
    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
</web-app>


Meu faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xi="http://www.w3.org/2001/XInclude" 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-facesconfig_1_2.xsd">
    <application>
        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
    </application>
    <managed-bean>
        <description>User Name Bean</description>
        <managed-bean-name>customerBean</managed-bean-name>
        <managed-bean-class>br.com.jm.spring.customer.db.CustomerBean
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/pages/inputUserName.jsp
        </from-view-id>
        <navigation-case>
            <from-outcome>hello</from-outcome>
            <to-view-id>/pages/hello.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>
</faces-config>


Meu Bean

public class CustomerBean{
   
    private CustomerService customerService;
    private Customer customer;
   
    public User(){
       
        customer = new Customer();
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
   
    public String cadastrar(){
        customerService.createCustomer(customer);
        return "hello";
    }


}

fiz uns teste e conseguir inserir normalmente, consigo levantar normalmente no meu servidor de aplicações com spring e jsf todo configurado so que quando aciono meu botao gravar da esse erro alguem poderia me ajudar, tenho que entregar um projeto e tenho mas  30 dias aguardo a ajuda dos senhores.

Segue o Erro...

03/12/2009 15:58:11 com.sun.faces.application.ActionListenerImpl processAction
SEVERE: java.lang.NullPointerException
javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
    at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
    at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
    at br.com.jm.spring.customer.db.CustomerBean.cadastrar(CustomerBean.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    ... 28 more
03/12/2009 15:58:11 com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{customerBean.cadastrar}: java.lang.NullPointerException
javax.faces.FacesException: #{customerBean.cadastrar}: java.lang.NullPointerException
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
    at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
    at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    ... 27 more
Caused by: java.lang.NullPointerException
    at br.com.jm.spring.customer.db.CustomerBean.cadastrar(CustomerBean.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    ... 28 more
03/12/2009 15:58:11 com.sun.faces.lifecycle.LifecycleImpl phase
WARNING: executePhase(INVOKE_APPLICATION 5,com.sun.faces.context.FacesContextImpl@898587) threw exception
javax.faces.FacesException: #{customerBean.cadastrar}: java.lang.NullPointerException
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:105)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.faces.FacesException: #{customerBean.cadastrar}: java.lang.NullPointerException
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
    at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
    at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    ... 21 more
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    ... 27 more
Caused by: java.lang.NullPointerException
    at br.com.jm.spring.customer.db.CustomerBean.cadastrar(CustomerBean.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    ... 28 more
03/12/2009 15:58:11 org.ajax4jsf.webapp.BaseXMLFilter doXmlFilter
SEVERE: Exception in the filter chain
javax.servlet.ServletException: #{customerBean.cadastrar}: java.lang.NullPointerException
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
Caused by: javax.faces.FacesException: #{customerBean.cadastrar}: java.lang.NullPointerException
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
    at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
    at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    ... 18 more
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    ... 27 more
Caused by: java.lang.NullPointerException
    at br.com.jm.spring.customer.db.CustomerBean.cadastrar(CustomerBean.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    ... 28 more
03/12/2009 15:58:11 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
    at br.com.jm.spring.customer.db.CustomerBean.cadastrar(CustomerBean.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:172)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
    at javax.faces.component.UICommand.broadcast(UICommand.java:383)
    at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
    at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
    at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)











Responder

Posts

04/12/2009

Marco Monteiro

O Erro estava eu estava tentando declarar no meu faces meu managedBean onde o mesmo tem que ser declarado no meu applicationContext  com a tag adicionada para reconhecimento das anotações
    <context:component-scan base-package="br.com.jm.spring.customer.db.service" /> e ficou tudo legal abraços a todos

Pessoal depois de algumas alterações consegui rodar a aplicação segue as alterações

Meu ManagedBean

@Controller("customerBean")
@Scope("session")
public class CustomerBean {
   
    @Resource
    private CustomerService customerService;
    private Customer customer;
   
    public CustomerBean(){
       
        customer = new Customer();
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
   
   
    public String cadastrar(){
        System.out.println("Nome:"+customer.getName());
        System.out.println("EMail:"+customer.getEmail());
        customerService.createCustomer(customer);
       
        return "hello";
    }


}

*********************************************************

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xi="http://www.w3.org/2001/XInclude" 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-facesconfig_1_2.xsd">
    <application>
        <variable-resolver>
            org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
    </application>
    <navigation-rule>
        <from-view-id>/pages/inputUserName.jsp</from-view-id>
        <navigation-case>
            <from-outcome>hello</from-outcome>
            <to-view-id>/pages/hello.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

Responder
×
+1 DevUP
Acesso diário, +1 DevUP
Parabéns, você está investindo na sua carreira