Configuration Tomcat + Jsf + IceFaces + Spring/JPA/Hibernat
Bonjour à tous,
J'ai lu la FAQ Spring et fait des tests sans succés :-( je suis un peu désarçonné ! .... le session bean ne s'instancie pas en raison, je pense, de la
rèf sur ApplicationBean1 et l'appel au contexte d'application Spring mais je ne suis sûr de rien ...
Premier post ... premier dév en J2SE .... trois semaines dans les forums et internet et des comportements ... obscurs de mon appli en cours de montage ...
Contexte : Mise en place d'une application en Tomcat 6.0.18 car je ne peux pas utiliser un serveur d'applications. Comme les fonctionnalités Ajax et Serveur Push me sont utiles j'ai choisi le framework IceFaces et donc JSF1.2 . Vu que je dois me lier à des bases de données susceptibles de varier j'utilise l'interface JPA implémentée par Hibernate. Comme l'aspect transactionnel managé me semble bonne je passe par Spring pour obtenir le JPA managé. Tout ça sous l'IDE NetBeans 6.5
La question : J'avoue me perdre dans les fichiers de configuration, j'ai bien réussi à obtenir un fonctionnement de l'ensemble mais au prix de gros mals de tête et je ne suis pas sûr du tout que tout soit bien. En effet, je mets le fichiers de configuration spring.xml dans un package par défaut de Source Packages, le fichier faces-config.xml dans le dossier Configuration Files. Mais quels fichiers sont utilisés par Tomcat pour tout mettre en place ? Dans quel ordre ? Est ce que je peux injecté une référence à deux beans managés par JSF ( ex : SessionBean1 a une référence sur ApplicationBean1 ) sachant que l'un d'entre eux ( ApplicationBean1 ) à besoin d'une référence sur un bean managé par Spring ( je demande en effet de créer une variable avec le contexte d'application Spring pour obtenir un objet entitymanager .... ) ? J'obtiens en effet ""com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: aa.SessionBean1""
Merci de me dire si je dois présenter les choses autrement ou tout autre conseil ou avis.
Yann
Voici mes fichiers :
faces-config.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
|
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
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">
<application>
<view-handler>
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl
</view-handler>
</application>
<managed-bean>
<managed-bean-name>ApplicationBean1</managed-bean-name>
<managed-bean-class>aa.ApplicationBean1</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>SessionBean1</managed-bean-name>
<managed-bean-class>aa.SessionBean1</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>applicationBean1</property-name>
<value>ApplicationBean1</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>RequestBean1</managed-bean-name>
<managed-bean-class>aa.RequestBean1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>Page1</managed-bean-name>
<managed-bean-class>aa.Page1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config> |
applicationContext.xmlpour Spring
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
|
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/jpa"
p:username="root"
p:password=""/>
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<!-- 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="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>
<!-- 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> |
SessionBean1
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
* SessionBean1.java
*
* Created on 30 avr. 2009, 14:30:34
* Copyright Administrateur
*/
package aa;
import java.util.logging.*;
import java.io.*;
import com.sun.rave.web.ui.appbase.AbstractSessionBean;
import javax.faces.FacesException;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import service.IService;
import entites.Personne;
import java.util.Arrays;
import java.util.Comparator;
/**
* <p>Session scope data bean for your application. Create properties
* here to represent cached data that should be made available across
* multiple HTTP requests for an individual user.</p>
*
* <p>An instance of this class will be created for you automatically,
* the first time your application evaluates a value binding expression
* or method binding expression that references a managed bean using
* this class.</p>
*/
public class SessionBean1 {
//instanciée via le système de managment de JSF via faces-config.xml
private ApplicationBean1 applicationBean1;
private static Logger logger = Logger.getLogger("aa");
private FileHandler fh ;
private Boolean bDejaPasse = false;
private int iCount;
private IService service = null;
private List<Personne> data ;
private Personne[] TabPersonnes;
private String prenomColumnName;
private String sortColumnName;
private Boolean ascending;
private String oldSort;
private Boolean oldAscending;
public SessionBean1(){
iCount=0;
data = applicationBean1.getService().getAll();
TabPersonnes = (Personne[]) data.toArray(new Personne[data.size()]);
sortColumnName = "prenom";
ascending = true;
prenomColumnName = "prenom";
oldSort = sortColumnName;
// make sure sortColumnName on first render
oldAscending = !ascending;
bDejaPasse=false;
}
/*
* This method is called from faces-config.xml with each new session.
*/
public void setapplicationBean1(ApplicationBean1 applicationBean) {
this.applicationBean1 = applicationBean;
}
public void setbDejaPasse(boolean LaValeur){
bDejaPasse=LaValeur;
}
public void setdata(List<Personne> MesData){
data = MesData;
}
public IService getService(){
return service;
}
public Personne[] getTabPersonnes() throws IOException{
/* Pour le système de Log */
fh = new FileHandler("log.out");
// Send logger output to FileHandler.
logger.addHandler(fh);
// Log all
logger.setLevel(Level.FINE);
// if (bDejaPasse!=false){
bDejaPasse=true;
if (!oldSort.equals(sortColumnName) || oldAscending != ascending){
sort();
oldSort = sortColumnName;
oldAscending = ascending;
String strMessage = "in - getTabPersonnes";
logger.log(Level.FINE, strMessage);
}
// }else{
// String strMessage = "out - getTabPersonnes";
// logger.log(Level.FINE, strMessage);
// }
return TabPersonnes;
}
public String getoldSort(){
return this.oldSort;
}
public void setoldSort(String TheoldSort){
this.oldSort=TheoldSort;
}
public Boolean getoldAscending(){
return this.oldAscending;
}
public void setoldAscending(Boolean TheoldAscending){
this.oldAscending=TheoldAscending;
}
public String getprenomColumnName(){
return this.prenomColumnName;
}
public void setprenomColumnName(String ThePrenomColumnName){
this.prenomColumnName=ThePrenomColumnName;
}
public String getsortColumnName(){
return this.sortColumnName;
}
public void setsortColumnName(String ThesortColumnName){
this.oldSort = this.sortColumnName;
this.sortColumnName=ThesortColumnName;
}
public Boolean getascending(){
return this.ascending;
}
public void setascending(Boolean Theascending){
this.oldAscending = this.ascending;
this.ascending=Theascending;
}
public boolean isAscending() {
return ascending;
}
protected boolean isDefaultAscending(String sortColumn) {
return true;
}
public void sort() throws IOException {
/* Pour le système de Log */
fh = new FileHandler("log.out");
// Send logger output to FileHandler.
logger.addHandler(fh);
// Log all
logger.setLevel(Level.FINE);
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
Personne c1 = (Personne) o1;
Personne c2 = (Personne) o2;
if (sortColumnName == null) {
String strMessage = "in null ";
logger.log(Level.FINE, strMessage);
return 0;
}
if (sortColumnName.equals(prenomColumnName)) {
String strMessage = "not in null, comparaison de "+c1.getPrenom()+" et "+c2.getPrenom();
logger.log(Level.FINE, strMessage);
return ascending ? c1.getPrenom().compareTo(c2.getPrenom()) : c2.getPrenom().compareTo(c1.getPrenom());
} else return 0;
}
};
String strMessage = "et alors";
logger.log(Level.FINE, strMessage);
Arrays.sort(TabPersonnes, comparator);
// String mymess = TabPersonnes.toString();
// logger.log(Level.FINE, mymess);
}
} |
ApplicationBean1
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
* ApplicationBean1.java
*
* Created on 30 avr. 2009, 14:30:34
* Copyright Administrateur
*/
package aa;
import com.sun.rave.web.ui.appbase.AbstractApplicationBean;
import javax.faces.FacesException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.IService;
/**
* <p>Application scope data bean for your application. Create properties
* here to represent cached data that should be made available to all users
* and pages in the application.</p>
*
* <p>An instance of this class will be created for you automatically,
* the first time your application evaluates a value binding expression
* or method binding expression that references a managed bean using
* this class.</p>
*/
public class ApplicationBean1 extends AbstractApplicationBean {
// service
private IService service = null;
private ApplicationContext ctx = null;
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
private int __placeholder;
/**
* <p>Automatically managed component initialization. <strong>WARNING:</strong>
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.</p>
*/
private void _init() throws Exception {
}
// </editor-fold>
public IService getService(){
return service;
}
public ApplicationContext getApplicationContext(){
return ctx;
}
/**
* <p>Construct a new application data bean instance.</p>
*/
public ApplicationBean1() {
ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
// couche service
service = (IService) ctx.getBean("service");
}
/**
* <p>This method is called when this bean is initially added to
* application scope. Typically, this occurs as a result of evaluating
* a value binding or method binding expression, which utilizes the
* managed bean facility to instantiate this bean and store it into
* application scope.</p>
*
* <p>You may customize this method to initialize and cache application wide
* data values (such as the lists of valid options for dropdown list
* components), or to allocate resources that are required for the
* lifetime of the application.</p>
*/
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here
// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("ApplicationBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}
/**
* <p>This method is called when this bean is removed from
* application scope. Typically, this occurs as a result of
* the application being shut down by its owning container.</p>
*
* <p>You may customize this method to clean up resources allocated
* during the execution of the <code>init()</code> method, or
* at any later time during the lifetime of the application.</p>
*/
public void destroy() {
}
/**
* <p>Return an appropriate character encoding based on the
* <code>Locale</code> defined for the current JavaServer Faces
* view. If no more suitable encoding can be found, return
* "UTF-8" as a general purpose default.</p>
*
* <p>The default implementation uses the implementation from
* our superclass, <code>AbstractApplicationBean</code>.</p>
*/
public String getLocaleCharacterEncoding() {
return super.getLocaleCharacterEncoding();
}
} |
Page1.jsp qui doit afficher un tableau avec les éléments extraits de la BdD. C'est ici ( si j'ai bien compris ) que l'Page1 fait appel à SessionBean1 qui s'intancie donc ( puisque pas encore créer et qui lit-même fait appel à ApplicationBean qui se crée donc et fournit le contexte d'application Spring pour accéder à JPA .... Je suis pas sûr du tout d'avoir tout bien saisi ... !
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 98
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : Page1
Created on : 30 avr. 2009, 14:30:34
Author : Administrateur
-->
<jsp:root version="2.0" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:jsp="http://java.sun.com/JSP/Page">
<jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
<f:view>
<html id="outputHtml1">
<head id="outputHead1">
<ice:outputStyle href="./resources/stylesheet.css" id="outputStyle1"/>
<ice:outputStyle href="./resources/csspourtableau.css" id="outputStyle3"/>
<ice:outputStyle href="./xmlhttp/css/xp/xp.css" id="outputStyle2"/>
</head>
<body id="outputBody1" style="-rave-layout: grid">
<ice:form id="form1" partialSubmit="true" style="background-color: green; height: 456px; left: 48px; top: 120px; position: absolute; width: 720px">
<ice:dataPaginator fastStep="2" for="tableauPersonnes" id="dataScroll_3" paginator="true" paginatorMaxPages="4">
<f:facet name="first">
<ice:graphicImage style="border:none;" title="Première page" url="./xmlhttp/css/xp/css-images/arrow-first.gif"/>
</f:facet>
<f:facet name="last">
<ice:graphicImage style="border:none;" url="./xmlhttp/css/xp/css-images/arrow-last.gif"/>
</f:facet>
<f:facet name="previous">
<ice:graphicImage style="border:none;" url="./xmlhttp/css/xp/css-images/arrow-previous.gif"/>
</f:facet>
<f:facet name="next">
<ice:graphicImage style="border:none;" url="./xmlhttp/css/xp/css-images/arrow-next.gif"/>
</f:facet>
<f:facet name="fastforward">
<ice:graphicImage style="border:none;" url="./xmlhttp/css/xp/css-images/arrow-ff.gif"/>
</f:facet>
<f:facet name="fastrewind">
<ice:graphicImage style="border:none;" url="./xmlhttp/css/xp/css-images/arrow-fr.gif"/>
</f:facet>
</ice:dataPaginator>
<ice:dataTable columnClasses="prenomColumn, nomColumn, datenaissanceColumn, marieColumn,nbenfantsColumn" id="tableauPersonnes"
rowClasses="evenRow,oddRow" rows="3" value="#{SessionBean1.tabPersonnes}" var="ElementDeListe">
<ice:rowSelector value="#{customerbean.expanded}" selectedClass="tableRowSelected" mouseOverClass="tableRowMouseOver" toggleOnClick="false"/>
<!-- Prénom -->
<ice:column>
<f:facet name="header">
<ice:commandSortHeader rendered="#{SessionBean1.prenomColumnName}" arrow="true" columnName="#{SessionBean1.prenomColumnName}">
<ice:commandLink action="#{Page1.button2_action}">
<ice:outputText value="Prénom"/>
</ice:commandLink>
</ice:commandSortHeader>
</f:facet>
<ice:outputText value="#{ElementDeListe.prenom}"/>
</ice:column>
<!-- Nom -->
<ice:column>
<f:facet name="header">
<ice:outputText value="Nom"/>
</f:facet>
<ice:outputText value="#{ElementDeListe.nom}"/>
</ice:column>
<ice:column>
<f:facet name="header">
<ice:outputText value="Date de naissance"/>
</f:facet>
<ice:outputText value="#{ElementDeListe.datenaissance}"/>
</ice:column>
<ice:column>
<f:facet name="header">
<ice:outputText value="Marié(e) ?"/>
</f:facet>
<ice:outputText value="#{ElementDeListe.marie}"/>
</ice:column>
<ice:column>
<f:facet name="header">
<ice:outputText value="Nombre d'enfants"/>
</f:facet>
<ice:outputText value="#{ElementDeListe.nbenfants}"/>
</ice:column>
</ice:dataTable>
<ice:dataPaginator displayedRowsCountVar="displayedRowsCount" firstRowIndexVar="firstRowIndex" for="tableauPersonnes" id="dataScroll_2"
lastRowIndexVar="lastRowIndex" pageCountVar="pageCount" pageIndexVar="pageIndex" rowsCountVar="rowsCount">
<ice:outputFormat styleClass="standard" value="{0} personnes trouvées, affichage de {1} personnes(s), de {2} à {3}. Page {4} / {5}.">
<f:param value="#{rowsCount}"/>
<f:param value="#{displayedRowsCount}"/>
<f:param value="#{firstRowIndex}"/>
<f:param value="#{lastRowIndex}"/>
<f:param value="#{pageIndex}"/>
<f:param value="#{pageCount}"/>
</ice:outputFormat>
</ice:dataPaginator>
</ice:form>
</body>
</html>
</f:view>
</jsp:root> |
Pour finir, le fichier de persistence
persistence.xml qui se trouve dans Configuration Files
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entites.Personne</class>
<properties>
<property name="hibernate.archive.autodetection" value="class,hbm"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence> |
Voilà, j'espère que quelqu'un pourra voir ce qu'il y a à voir ! Merci
Modifications dans les fichiers de config .... ça a l'air mieux ...
J'ai modifié les fichiers de configuration de config, bon ça ne marche toujours pas mais ça me semble mieux.
Je me suis appuyé sur le post Blog à l'adresse suivante :
http://sjuneja.wordpress.com/2007/10...pring-and-jpa/
Donc j'ai modifié web.xml ; faces-config.xml , je tente d'injecter une référence sur l'Interface (Iservice) service (géré par Spring ) dans SessionBean1 (géré par JSF ) via faces-config.xml en utilisant DelegatingVariableResolver.
L'erreur dans le log Apache me dit que SessionBean1 can't be instantiate...
Vu que j'ai enlevé beaucoup de code pour comprendre d'où vient mon erreur voici les nouveaux fichiers :
fichier log
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
7 mai 2009 10:45:55 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
7 mai 2009 10:45:56 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
7 mai 2009 10:45:56 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
7 mai 2009 10:46:14 org.apache.catalina.core.ApplicationContext log
GRAVE: javax.el.ELException: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: aa.SessionBean1.
javax.faces.FacesException: javax.el.ELException: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: aa.SessionBean1.
at javax.faces.component.UIData.getValue(UIData.java:612)
ass.newInstance(Class.java:308)
at ... |
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<?xml version="1.0" encoding="UTF-8"?>
<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">
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.debugDOMUpdate</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>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>4048576</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.standardRequestScope</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/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>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>
<servlet-name>uploadServlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</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>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>uploadServlet</servlet-name>
<url-pattern>/uploadHtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app> |
fichier faces-config.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
|
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
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">
<application>
<view-handler>
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl
</view-handler>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
</application>
<managed-bean>
<managed-bean-name>ApplicationBean1</managed-bean-name>
<managed-bean-class>aa.ApplicationBean1</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>SessionBean1</managed-bean-name>
<managed-bean-class>aa.SessionBean1</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>service</property-name>
<value>#{service}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>RequestBean1</managed-bean-name>
<managed-bean-class>aa.RequestBean1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>Page1</managed-bean-name>
<managed-bean-class>aa.Page1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config> |
fichier applicationContext.xml que j'ai remis dans /WEB-INF/
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
|
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/jpa"
p:username="root"
p:password=""/>
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<!-- 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="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>
<!-- 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> |
fichier Application1.java
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* ApplicationBean1.java
*
* Created on 30 avr. 2009, 14:30:34
* Copyright Administrateur
*/
package aa;
import com.sun.rave.web.ui.appbase.AbstractApplicationBean;
import javax.faces.FacesException;
/**
* <p>Application scope data bean for your application. Create properties
* here to represent cached data that should be made available to all users
* and pages in the application.</p>
*
* <p>An instance of this class will be created for you automatically,
* the first time your application evaluates a value binding expression
* or method binding expression that references a managed bean using
* this class.</p>
*/
public class ApplicationBean1 extends AbstractApplicationBean {
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
private int __placeholder;
/**
* <p>Automatically managed component initialization. <strong>WARNING:</strong>
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.</p>
*/
private void _init() throws Exception {
}
// </editor-fold>
/**
* <p>Construct a new application data bean instance.</p>
*/
public ApplicationBean1() {
}
/**
* <p>This method is called when this bean is initially added to
* application scope. Typically, this occurs as a result of evaluating
* a value binding or method binding expression, which utilizes the
* managed bean facility to instantiate this bean and store it into
* application scope.</p>
*
* <p>You may customize this method to initialize and cache application wide
* data values (such as the lists of valid options for dropdown list
* components), or to allocate resources that are required for the
* lifetime of the application.</p>
*/
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here
// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("ApplicationBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}
/**
* <p>This method is called when this bean is removed from
* application scope. Typically, this occurs as a result of
* the application being shut down by its owning container.</p>
*
* <p>You may customize this method to clean up resources allocated
* during the execution of the <code>init()</code> method, or
* at any later time during the lifetime of the application.</p>
*/
public void destroy() {
}
/**
* <p>Return an appropriate character encoding based on the
* <code>Locale</code> defined for the current JavaServer Faces
* view. If no more suitable encoding can be found, return
* "UTF-8" as a general purpose default.</p>
*
* <p>The default implementation uses the implementation from
* our superclass, <code>AbstractApplicationBean</code>.</p>
*/
public String getLocaleCharacterEncoding() {
return super.getLocaleCharacterEncoding();
}
} |
fichier SessionBean1.java
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
/*
* SessionBean1.java
*
* Created on 30 avr. 2009, 14:30:34
* Copyright Administrateur
*/
package aa;
import java.io.*;
import com.sun.rave.web.ui.appbase.AbstractSessionBean;
import javax.faces.FacesException;
import java.util.List;
import service.IService;
import entites.Personne;
import java.util.Arrays;
import java.util.Comparator;
/**
* <p>Session scope data bean for your application. Create properties
* here to represent cached data that should be made available across
* multiple HTTP requests for an individual user.</p>
*
* <p>An instance of this class will be created for you automatically,
* the first time your application evaluates a value binding expression
* or method binding expression that references a managed bean using
* this class.</p>
*/
public class SessionBean1 extends AbstractSessionBean {
private IService service ; //instancié par Spring
private List<Personne> data ;
private Personne[] TabPersonnes;
private String prenomColumnName;
private String sortColumnName;
private Boolean ascending;
private String oldSort;
private Boolean oldAscending;
// <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
private int __placeholder;
/**
* <p>Automatically managed component initialization. <strong>WARNING:</strong>
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.</p>
*/
private void _init() throws Exception {
}
// </editor-fold>
/**
* <p>Construct a new session data bean instance.</p>
*/
public SessionBean1(){
data = service.getAll();
TabPersonnes = (Personne[]) data.toArray(new Personne[data.size()]);
sortColumnName = "prenom";
ascending = true;
prenomColumnName = "prenom";
oldSort = sortColumnName;
// make sure sortColumnName on first render
oldAscending = !ascending;
}
public void setservice(IService LeService){
service=LeService;
}
public Personne[] getTabPersonnes() throws IOException{
/* Pour le système de Log */
if (!oldSort.equals(sortColumnName) || oldAscending != ascending){
sort();
oldSort = sortColumnName;
oldAscending = ascending;
}
return TabPersonnes;
}
public String getoldSort(){
return this.oldSort;
}
public void setoldSort(String TheoldSort){
this.oldSort=TheoldSort;
}
public Boolean getoldAscending(){
return this.oldAscending;
}
public void setoldAscending(Boolean TheoldAscending){
this.oldAscending=TheoldAscending;
}
public String getprenomColumnName(){
return this.prenomColumnName;
}
public void setprenomColumnName(String ThePrenomColumnName){
this.prenomColumnName=ThePrenomColumnName;
}
public String getsortColumnName(){
return this.sortColumnName;
}
public void setsortColumnName(String ThesortColumnName){
this.oldSort = this.sortColumnName;
this.sortColumnName=ThesortColumnName;
}
public Boolean getascending(){
return this.ascending;
}
public void setascending(Boolean Theascending){
this.oldAscending = this.ascending;
this.ascending=Theascending;
}
/**
* <p>This method is called when this bean is initially added to
* session scope. Typically, this occurs as a result of evaluating
* a value binding or method binding expression, which utilizes the
* managed bean facility to instantiate this bean and store it into
* session scope.</p>
*
* <p>You may customize this method to initialize and cache data values
* or resources that are required for the lifetime of a particular
* user session.</p>
*/
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here
// <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("SessionBean1 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}
// </editor-fold>
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}
/**
* <p>This method is called when the session containing it is about to be
* passivated. Typically, this occurs in a distributed servlet container
* when the session is about to be transferred to a different
* container instance, after which the <code>activate()</code> method
* will be called to indicate that the transfer is complete.</p>
*
* <p>You may customize this method to release references to session data
* or resources that can not be serialized with the session itself.</p>
*/
public void passivate() {
}
/**
* <p>Return a reference to the scoped data bean.</p>
*
* @return reference to the scoped data bean
*/
protected ApplicationBean1 getApplicationBean1() {
return (ApplicationBean1) getBean("ApplicationBean1");
}
/**
* <p>This method is called when the session containing it was
* reactivated.</p>
*
* <p>You may customize this method to reacquire references to session
* data or resources that could not be serialized with the
* session itself.</p>
*/
public void activate() {
}
/**
* <p>This method is called when this bean is removed from
* session scope. Typically, this occurs as a result of
* the session timing out or being terminated by the application.</p>
*
* <p>You may customize this method to clean up resources allocated
* during the execution of the <code>init()</code> method, or
* at any later time during the lifetime of the application.</p>
*/
public void destroy() {
}
public boolean isAscending() {
return ascending;
}
protected boolean isDefaultAscending(String sortColumn) {
return true;
}
public void sort() throws IOException {
Comparator comparator = new Comparator() {
public int compare(Object o1, Object o2) {
Personne c1 = (Personne) o1;
Personne c2 = (Personne) o2;
if (sortColumnName == null) {
return 0;
}
if (sortColumnName.equals(prenomColumnName)) {
return ascending ? c1.getPrenom().compareTo(c2.getPrenom()) : c2.getPrenom().compareTo(c1.getPrenom());
} else return 0;
}
};
Arrays.sort(TabPersonnes, comparator);
// String mymess = TabPersonnes.toString();
// logger.log(Level.FINE, mymess);
}
} |
Merci 8O
Ca marche bien .... ou pas ....
Bonjour Skip, merci de ta réponse, ça fait du bien de se sentir compris ! Lol
Je suis dans le cas où tu étais avant puisqu'il s'agit de ma première expérience J2SE ....
Voilà, le bloc que tu m'as indiqué, je l'ai également vu ce matin dans le Post que j'ai mis en lien dans mon message N°2 et effectivement c'est beaucoup mieux. J'ai également ajouté
Code:
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
dans faces-config.xml et l'injection d'un bean Spring dans un bean managé JSF fonctionne correctement... :D
voici ce que j'ai dans mon log Apache, ... curieux qu'il n'y ait rien d'autre non ??
Code:
1 2 3 4 5 6 7 8 9 10 11
|
7 mai 2009 14:26:01 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
7 mai 2009 14:26:03 org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
7 mai 2009 14:26:03 org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
7 mai 2009 14:26:12 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
7 mai 2009 14:26:17 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext |
Donc tout est Ok, il reste alors une question que je suis en train de voir :
j'ai un bean de scope Session qui doit étendre une classe et implémenter deux interfaces, bon ça c'est Ok mais alors ..... comment faire pour que ce bean-là soit managé par JSF ?!?! puisque je ne peux plus mettre : extends AbstractSessionBean ... faut-il que je mette ça. En effet, avant j'avais :
Code:
public class SessionBean1 extends AbstractSessionBean
et maintenant je dois mettre un truc du style :
Code:
public class SessionBean extends DataSource implements Renderable, DisposableBean
.... mais alors plus rien ne s'instancie correctement ... Faut-il que je mette extends AbstractSessionBean sur DataSource ?? et dans ce cas je mets qui dans faces-config.xml ???? :roll:
En tout cas merci de t'être penché sur mon Pb :D
Yann
tests en cours - bean sans héritage
je teste ça tout de suite ...:lol: