comment configurer spring avec ICefaces
salut TLM
mon environnement :eclipse
j'ai commencé mon projet d'abord avec spring mais j'ai pas utilisé JSF (seulement des page jsp avec code html) et ca marche formidable
maintenant depuis une semaine :calim2: j'arrive pas a configuré spring avec l'utilisation de ICefaces avec le meme projet
j'ai téléchargé un exemple SPRINcrud mais:cry: j'ai pas arrivé a bien configuré
je utilise Spring /hibernate
mon dao
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package dao;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entites.Technicien;
public class Dao implements IDao {
@PersistenceContext
private EntityManager em;
//Technicien
// supprimer une Technicien via son identifiant
public void deleteOneTechnicien(String cin) {
Technicien technicien = em.find(Technicien.class, cin);
if (technicien == null) {
throw new DaoException(String.format("Technicien n°[%d] inconnue", cin), 2);
}
em.remove(technicien);
}
@SuppressWarnings("unchecked")
// obtenir toutes les Techniciens
public List<Technicien> getAllTechnicien() {
return em.createQuery("select t from Technicien t").getResultList();
}
@SuppressWarnings("unchecked")
// obtenir les propretaires dont le nom correspond àun modèle
public List<Technicien> getAllLikeTechnicien(String modele) {
return em.createQuery("select t from Technicien t where t.nom like :modele")
.setParameter("modele", modele).getResultList();
}
// obtenir un Technicien via son identifiant
public Technicien getOneTechnicien(String cin) {
return em.find(Technicien.class, cin);
}
// sauvegarder un Technicien
public Technicien saveOneTechnicien(Technicien technicien) {
em.persist(technicien);
return technicien;
}
// mettre à jour un Technicien
public Technicien updateOneTechnicien(Technicien technicien) {
Technicien t = em.find(Technicien.class, technicien.getCin());
if (t == null) {
throw new DaoException(String.format("Technicien n°[%d] inconnue", technicien.getCin()), 2);
}
return em.merge(technicien);
} |
ma couche service
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| package service;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import dao.IDao;
import entites.Administrateur;
import entites.Camion;
import entites.Chauffeur;
import entites.ClientFidele;
import entites.ClientPassager;
import entites.Compte;
import entites.Contrat;
import entites.DemandeVoyage;
import entites.Entreprise;
import entites.Message;
import entites.Individu;
import entites.Reponse;
import entites.Technicien;
import entites.Voyage;
//ttes les méthodes de la classe se déroulent dans une transaction
@Transactional
public class Service implements IService {
// couche [dao]
private IDao dao;
public IDao getDao() {
return dao;
}
public void setDao(IDao dao) {
this.dao = dao;
}
// supprimer une Technicien via son identifiant
public void deleteOneTechnicien(String cin) {
dao.deleteOneTechnicien(cin);
}
// obtenir toutes les Techniciens
public List<Technicien> getAllTechnicien(){
return dao.getAllTechnicien();
}
// obtenir les propretaires dont le nom correspond àun modèle
public List<Technicien> getAllLikeTechnicien(String modele) {
return dao.getAllLikeTechnicien(modele);
}
// obtenir un Technicien via son identifiant
public Technicien getOneTechnicien(String cin){
return dao.getOneTechnicien(cin);
}
// sauvegarder un Technicien
public Technicien saveOneTechnicien(Technicien technicien){
return dao.saveOneTechnicien(technicien);
}
// mettre à jour un Technicien
public Technicien updateOneTechnicien(Technicien technicien){
return dao.updateOneTechnicien(technicien);
} |
la couche web
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| package web;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.* ;
import net.sf.cglib.proxy.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.IService;
import dao.DaoException;
import entites.*;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
public class Tech {
private List<Technicien> techniciens;
// service
private IService service = null;
public Tech(){
}
// init
public void init() throws ServletException {
// configuration de l'application
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");
// couche service
service = (IService) ctx.getBean("service");
}
public String doListTechnicien(){
techniciens=service.getAllTechnicien();
System.out.println("ggggggggggggggggggg");
return "list";
}
public List<Technicien> getTechniciens() {
return techniciens;
}
public void setTechniciens(List<Technicien> techniciens) {
this.techniciens = techniciens;
}
} |
et j'ai un fichier spring-config pour configurer spring et hibernate c'est le même que l'ancien projet avant l'utilisation de ICefaces
sppring-config
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- couches applicatives -->
<bean id="dao" class="dao.Dao" />
<bean id="service" class="service.Service">
<property name="dao" ref="dao" />
</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="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="generateDdl" value="true" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<!-- la source de donnéees DBCP -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/jpa" />
<property name="username" value="jpa" />
<property name="password" value="jpa" />
</bean>
<!-- le gestionnaire de transactions -->
<tx:annotation-driven transaction-manager="txManager" />
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- traduction des exceptions -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<!-- persistence -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
</beans> |
mon fichier web.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| <?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>exemple</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>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
<context-param>
<description>To allow multiple windows for a single application.</description>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>Turn on/off application-wide synchronous or asynchronous updates. </description>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>Google Maps API key is required if gMap component is used. Sign up for an API key from http://code.google.com/apis/maps/signup.html</description>
<param-name>com.icesoft.faces.gmapKey</param-name>
<param-value>ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>4048576</param-value>
</context-param>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
<url-pattern>*.jspx</url-pattern>
<url-pattern>/xmlhttp/*</url-pattern>
<url-pattern>*.faces</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>uploadServlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>uploadServlet</servlet-name>
<url-pattern>/uploadHtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</listener-class>
</listener>
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app> |
mon fichier face-config
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| <?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_1_2.xsd"
version="1.2">
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config xmlns="http://java.sun.com/JSF/Configuration">-->
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>tech</managed-bean-name>
<managed-bean-class>web.Tech</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>list</display-name>
<from-view-id>/acui.jspx</from-view-id>
<navigation-case>
<from-outcome>list</from-outcome>
<to-view-id>/cherche.jspx</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
<locale-config />
</application>
<lifecycle />
<factory />
</faces-config> |
merci pour m'aidé