Announcement Announcement Module
Collapse
No announcement yet.
Integration Spring 3.0 with jsf 2.0 and eclipselink jpa 2.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integration Spring 3.0 with jsf 2.0 and eclipselink jpa 2.1

    i'm using Eclipse Helios with Oracle Enterprise Pack. I'm new in jsf and spring.
    I installed the library for jpa 2.1 and i genenrated Entities from Tables, after I generated Spring ORM CLASES, and after i created a java Beans, i tested with Junit, and is rigth.

    The problems is with integration of JSF 2.0 and Spring, when run my page home.jsp display the object, but when inserted the register i had the next error:

    Caused by: java.lang.NullPointerException
    at test.EmpInsert.testPersistDepartment(EmpInsert.jav a:56)

    In the Beans testpersistDepartment.

    The configuration of the applicationContext.xml

    <?xml version="1.0" encoding="UTF-8" standalone="no"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">



    <!--bean post-processor for JPA annotations-->
    <bean class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor">
    </bean>

    <!--Exception translation bean post processor-->
    <bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor">
    </bean>

    <!--Transaction manager for a single JPA EntityManager (alternative to JTA)-->
    <bean class="org.springframework.orm.jpa.LocalEntityMana gerFactoryBean" id="entityManagerFactory">
    <property name="persistenceUnitName" value="TESTWEB"/>
    </bean>
    <bean class="org.springframework.orm.jpa.JpaTransactionM anager" id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>


    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean class="delegate.MultasSpringService" id="MultasService">
    <property name="dao">
    <bean class="delegate.MultasJPADao"/>
    </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    <property name="username" value="test"/>
    <property name="password" value="123456"/>
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="dataSource"/>
    </bean>
    </beans>

    The File Face-config.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">
    <application>
    <message-bundle>resources.application</message-bundle>
    <locale-config>
    <default-locale>en</default-locale>
    </locale-config>
    </application>
    <application>
    <el-resolver>org.springframework.web.jsf.el.SpringBean FacesELResolver</el-resolver>
    </application>
    <managed-bean>
    <managed-bean-name>empInsert</managed-bean-name>
    <managed-bean-class>test.EmpInsert</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
    <display-name>home</display-name>
    <from-view-id>/home.jsp</from-view-id>
    <navigation-case>
    <from-outcome>success</from-outcome>
    <to-view-id>/result.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    </faces-config>

    the File web.xml

    <?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>TESTWEB</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <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>
    </web-app>

    The file home.jsp with jsf

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <f:view>

    <h:form id="empInsertForm">
    <hanelGrid columns="3" border="1">
    <f:facet name="header">
    <h:outputText value="empInsert"></h:outputText>
    </f:facet>
    <h:outputText value="Id:"></h:outputText>
    <h:inputText id="id" value="#{empInsert.id}"></h:inputText>
    <h:message for="id"></h:message>
    <h:outputText value="Name:"></h:outputText>
    <h:inputText id="name" value="#{empInsert.name}"></h:inputText>
    <h:message for="name"></h:message>
    <h:outputText value="Pass:"></h:outputText>
    <h:inputText id="pass" value="#{empInsert.pass}"></h:inputText>
    <h:message for="pass"></h:message>
    </hanelGrid>
    <h:commandButton action="#{empInsert.testPersistDepartment}"
    value="success"></h:commandButton>
    </h:form>
    </f:view>
    </body>
    </html>

    And my beans EmpInsert.java

    package test;

    import org.springframework.beans.factory.annotation.Autow ired;

    import beans.Empleado;

    import delegate.IMultasService;

    public class EmpInsert {

    @Autowired
    private IMultasService departmentDelegate = null;
    private long id;
    private String name;
    private String pass;

    public IMultasService getDepartmentDelegate() {
    return departmentDelegate;
    }

    public void setDepartmentDelegate(IMultasService departmentDelegate) {
    this.departmentDelegate = departmentDelegate;
    }

    public long getId() {
    return id;
    }

    public void setId(long id) {
    this.id = id;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    public String getPass() {
    return pass;
    }

    public void setPass(String pass) {
    this.pass = pass;
    }

    public String testPersistDepartment() throws Exception {

    Empleado department = new Empleado();
    department.setId(getId());
    department.setNombre(getName());
    department.setPass(getPass());
    departmentDelegate.persistEmpleado(department);
    return "Fin";

    }

    }


    I need your help, with this nullpointer.... Thank you
Working...
X