dimanche 22 février 2015

Spring 2.5 and JSF integration

I try to integrate Jsf and Spring 2.5 in a simple application which will bring data from database.


this is my model.



@Entity
@Table(name = "t1")
public class T1 implements java.io.Serializable {

private static final long serialVersionUID = -1349562571118620319L;
private Integer id;
private String c1;
private String c2;

public T1() {
}

public T1(String c1, String c2) {
this.c1 = c1;
this.c2 = c2;
}

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}

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

@Column(name = "c1", length = 45)
public String getC1() {
return this.c1;
}

public void setC1(String c1) {
this.c1 = c1;
}

@Column(name = "c2", length = 45)
public String getC2() {
return this.c2;
}

public void setC2(String c2) {
this.c2 = c2;
}
}


This is my DAO interface



package com.plmV6.dao;

import com.plmV6.model.T1;

public interface T1Dao {
T1 findAll();
String cal();
}


this is the implementation



package com.plmV6.daoImpl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.plmV6.dao.T1Dao;
import com.plmV6.model.T1;
@Repository
@Transactional
public class T1DaoImpl implements T1Dao {
@PersistenceContext(unitName="plmV6")
EntityManager em;
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Transactional(readOnly=true)
public T1 findAll() {

T1 t=em.find(T1.class,1);
return t;

}

public String cal() {
// TODO Auto-generated method stub

return message;
}

}


My managedBean



package com.plmV6.Bean;

import javax.faces.bean.ManagedProperty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.plmV6.dao.T1Dao;
import com.plmV6.model.T1;

@Component("t1Bean")
@Scope("session")
public class T1Bean {

@ManagedProperty("#{t1DaoImpl}")
T1Dao t;
private String messageHello;
public void setMessageHello(String messageHello) {
this.messageHello = messageHello;
}
public String getMessageHello() {
return messageHello;
}


@Autowired
public void setT(T1Dao t) {
this.t = t;
}
public T1Dao getT() {

return t;
}

public String tCal(){
return t.cal();
}

private T1 tt;

public T1 getTt() {
tt=t.findAll();
return tt;
}
public void setTt(T1 tt) {
this.tt = tt;
}

public T1 getT11() {
return t.findAll();

}
}


applicationContext.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:context="http://ift.tt/GArMu7"
xmlns:jee="http://ift.tt/OpNaZ5"
xmlns:jms="http://ift.tt/1iMF6wC"
xmlns:lang="http://ift.tt/OGfeTY"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:util="http://ift.tt/OGfeTW"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/GAf8ZW
http://ift.tt/OpNdV1 http://ift.tt/OGfcLK
http://ift.tt/GArMu7 http://ift.tt/1bb5cbf
http://ift.tt/OpNaZ5 http://ift.tt/OGffai
http://ift.tt/1iMF6wC http://ift.tt/1BuJ5p4
http://ift.tt/OGfeTY http://ift.tt/OGffak
http://ift.tt/OGfeU2 http://ift.tt/OGffan
http://ift.tt/OGfeTW http://ift.tt/OGffag">


<context:annotation-config/>
<context:component-scan base-package="com.plmV6.Bean" />
<context:component-scan base-package="com.plmV6.daoImpl" />

</beans>


Web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/nSRXKP" xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/1eWqHMP" id="WebApp_ID" version="3.0">
<display-name>plmV6</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</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>


and faces-config.xml



<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://ift.tt/19L2NlC"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1mXF9WB"
version="2.2">
<application>
<message-bundle>resources.application</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>

<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>

</application>

</faces-config>


The console's message : Nothing shows in the index.xhtml : http://localhost:8080/plmV6/faces/index.xhtml



12:14:15,230 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found plmV6.war in deployment directory. To trigger deployment create a file called plmV6.war.dodeploy
12:14:15,242 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "plmV6.war"
12:14:16,542 INFO [org.jboss.as.jpa] (MSC service thread 1-1) JBAS011401: Read persistence.xml for plmV6
12:14:16,890 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
12:14:16,917 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
12:14:16,920 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
12:14:16,922 WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010402: Unable to instantiate driver class "com.mysql.jdbc.Driver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.plmV6_warcom_mysql_jdbc_Driver_5_1 is already registered
12:14:16,925 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
12:14:16,927 WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010402: Unable to instantiate driver class "com.mysql.fabric.jdbc.FabricMySQLDriver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.plmV6_warcom_mysql_fabric_jdbc_FabricMySQLDriver_5_1 is already registered
12:14:16,938 INFO [org.jboss.as.jpa] (MSC service thread 1-2) JBAS011402: Starting Persistence Unit Service 'plmV6.war#plmV6'
12:14:16,940 INFO [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH000204: Processing PersistenceUnitInfo [
name: plmV6
...]
12:14:16,979 WARN [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
12:14:16,982 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-2) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
12:14:16,984 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-2) HHH000422: Disabling contextual LOB creation as connection was null
12:14:16,985 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-2) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
12:14:16,988 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-2) HHH000397: Using ASTQueryTranslatorFactory
12:14:17,047 WARN [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-2) HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
12:14:17,164 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/plmV6]] (MSC service thread 1-5) Initializing Spring root WebApplicationContext
12:14:17,166 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization started
12:14:17,205 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-5) Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1d0647b: display name [Root WebApplicationContext]; startup date [Sun Feb 22 12:14:17 WET 2015]; root of context hierarchy
12:14:17,247 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-5) Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1d0647b]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1d53e62
12:14:17,260 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-5) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d53e62: defining beans []; root of factory hierarchy
12:14:17,262 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-5) Root WebApplicationContext: initialization completed in 95 ms
12:14:17,276 INFOS [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-5) Initialisation de Mojarra 2.1.7-jbossorg-1 (20120227-1401) pour le contexte «/plmV6»
12:14:21,902 INFO [org.jboss.web] (MSC service thread 1-5) JBAS018210: Registering web context: /plmV6
12:14:22,137 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "plmV6.war"


pleaase help. Thank you.


Aucun commentaire:

Enregistrer un commentaire