Bonjour,

je suis débutant et je voudrais développer une appli avec Spring, Hibernate et JSF.

Mon problème est que je veux utiliser une liste déroulante dans un JSF et j'ai toujours des messages d'erreur.

Sources utilisés :
-->index.jsf
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>    
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<title>MEDIAGEST - Gestion de médiathèque personnelle</title>
 
</head>
<body>
<f:loadBundle var="msg" basename="fr.ducrocql.dao.message" />
<div align="center">
Bienvenue dans l'application MEDIAGEST.
Gestion de médiathèque personnelle.
<br />
 
<h:form>
  <h:commandLink action="#{interpreteBean.gererInterprete}" value="#{msg.boutongestionInterp}" />
  &nbsp;&nbsp;&nbsp;&nbsp;
  <h:commandLink action="#{disqueBean.gererDisque}" value="Gérer disques">
  </h:commandLink>
  &nbsp;&nbsp;&nbsp;&nbsp;
  <h:commandLink action="#{cassetteBean.gererCassette}" value="Gérer cassettes"></h:commandLink>
  &nbsp;&nbsp;&nbsp;&nbsp;
  <h:commandLink action="#{livreBean.gererLivre}" value="Gérer livres"></h:commandLink>
  <br>
  <h:commandLink value="test" action="#{formatBean.gererFormat}" />
</h:form>
 
</div>
</body>
</html>
</f:view>
--> testList.jsf
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>    
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
</head>
<body>
<h:form>
	 	<h:outputLabel>Format</h:outputLabel>
		<h:selectOneMenu value="#{formatBean.libelle}" id="chx">  
		<f:selectItems value="#{formatBean.tousFormats}"/> 
	</h:selectOneMenu>  
	<h:commandButton value="ok" />
 
</h:form>
</body>
</html>
</f:view>
--> FormatBean
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
/*
 * Created on 15 juin 2009
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.ducrocql.beans;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.faces.model.SelectItem;
 
import fr.ducrocql.model.Format;
import fr.ducrocql.services.FormatService;
import fr.ducrocql.utils.Utils;
 
/**
 * @author Laurent
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class FormatBean {
	private FormatService formatService = (FormatService)Utils.getContext().getBean("formatService"); 
	private List<SelectItem> tousFormats = new ArrayList<SelectItem>();
 
	private int idFormat;
	private String libelle;
 
	@SuppressWarnings("unchecked")
	private Map session;
 
    /*
	 ********************************************************************************************************
	 * Méthodes                                                                                             *
	 ********************************************************************************************************
	 */
	public String creerFormat() {
		formatService.createFormat(libelle);
		return "formatOk";
	}
 
	public List<SelectItem> allFormats() {
		if (tousFormats == null) {
			try {
				tousFormats = formatService.getAllFormats();
			} catch (Exception e) {
			}
		}
		return tousFormats.subList(1, 1);
	}
 
    public String gererFormat() {
    	tousFormats = null;
    	allFormats();
    	return "test";
	}
 
    public String modifierFormat() {
    	formatService.editFormat(idFormat, libelle);
		return "SUCCESS";
	}
 
    public String supprimerFormat() {
    	formatService.deleteFormat(idFormat);
		return "SUCCESS";
	}
 
	/*
	 ********************************************************************************************************
	 * Getters et Setters                                                                                   *
	 ********************************************************************************************************
	 */
	public FormatService getFormatService() {
		return formatService;
	}
 
	public void setFormatService(FormatService service) {
		formatService = service;
	}
 
    public List<SelectItem> getTousFormats() {
    	return tousFormats;
	}
 
	public void setTousFormats(List<SelectItem> tousFormats) {
		this.tousFormats = tousFormats;
	}
 
	public int getIdFormat() {
		return idFormat;
	}
 
	public void setIdFormat(int idFormat) {
		this.idFormat = idFormat;
	}
 
	public String getLibelle() {
		return libelle;
	}
 
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
 
 
	/*
	 * Autres
	 */
	@SuppressWarnings("unchecked")
	public Map getSession() {
		return session;
	}
	@SuppressWarnings("unchecked")
	public void setSession(Map session) {
		this.session = session;
	}
}
-->FormatDAO
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
package fr.ducrocql.dao;

import java.util.List;

import javax.faces.model.SelectItem;

import fr.ducrocql.model.Format;

public interface FormatDao {
	public void saveFormat (Format f);
	public void removeFormat (Format f);
	public Format getFormat(int fid);
	public List<SelectItem> getAll();
}

-->FormatDAOImpl
package fr.ducrocql.dao;

import java.util.List;

import javax.faces.model.SelectItem;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import fr.ducrocql.model.Format;
import fr.ducrocql.utils.HibernateUtil;

public class FormatDaoImpl extends HibernateDaoSupport implements FormatDao {

	public Format getFormat(int fid) {
		Session session = HibernateUtil.currentSession();
		Format f = (Format)session.load(Format.class, fid);
		return f;
	}
	
	public void saveFormat (Format f) {
		Session session = HibernateUtil.currentSession();
		session.save(f);
	}
	
	public void removeFormat (Format f) {
		Session session = HibernateUtil.currentSession();
		session.delete(f);
	}
	
	@SuppressWarnings("unchecked")
	public List<SelectItem> getAll() {
		return (List<SelectItem>) this.getHibernateTemplate().loadAll(Format.class);
	}
}
-->FormatService
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package fr.ducrocql.services;
 
import java.util.List;
 
import javax.faces.model.SelectItem;
 
public interface FormatService {
	public List<SelectItem> getAllFormats();
 
	public boolean editFormat(int idFormat, String libelle);
 
	public boolean deleteFormat(int id);
 
	public boolean createFormat(String libelle);
}
-->FormatServiceImpl
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
/*
 * Created on 18 mai 2009
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package fr.ducrocql.services;
 
import java.util.List;
 
import javax.faces.model.SelectItem;
 
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
 
import fr.ducrocql.dao.FormatDao;
import fr.ducrocql.model.Format;
import fr.ducrocql.utils.HibernateUtil;
import fr.ducrocql.utils.Utils;
 
 
public class FormatServiceImpl implements FormatService {
    private FormatDao FormatDao;
 
	public List<SelectItem> getAllFormats() {
		return this.FormatDao.getAll();
	}
 
	public boolean editFormat(int fid, String libelle) {
		Session session = HibernateUtil.currentSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			Format f = FormatDao.getFormat(fid);
			f.setLibelle(libelle);
			FormatDao.saveFormat(f);
			tx.commit();
		}
		catch(HibernateException e) {
			e.printStackTrace();
			if (tx != null) tx.rollback();
			return false;
		}
		HibernateUtil.closeSession();
		return true;
	}
 
	public boolean deleteFormat(int fid) {
		Session session = HibernateUtil.currentSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			Format f = FormatDao.getFormat(fid);
			FormatDao.removeFormat(f);
			tx.commit();
		}
		catch(HibernateException e) {
			e.printStackTrace();
			if (tx != null) tx.rollback();
			return false;
		}
		HibernateUtil.closeSession();
		return true;
	}
 
	public boolean createFormat(String libelle) {
		Session session = HibernateUtil.currentSession();
		Transaction tx = null;
		try {
			tx = session.beginTransaction();
			Format f = (Format)Utils.getContext().getBean("Format");
			f.setLibelle(libelle);
			FormatDao.saveFormat(f);
			tx.commit();
		}
		catch(HibernateException e) {
			e.printStackTrace();
			if (tx != null) tx.rollback();
			return false;
		}
		HibernateUtil.closeSession();
		return true;
	}
 
	public FormatDao getFormatDao() {
		return FormatDao;
	}
 
	public void setFormatDao(FormatDao formatDao) {
		this.FormatDao = formatDao;
	}
}
pour démarrer, j'exécute index.jsf et je clique sur 'test'.
J'obtiens alors le message d'erreur :
An option for component chx was not an instance of javax.faces.model.SelectItem. Type found: java.util.ArrayList.

NB: la BDD est sous MySQL et j'y accède sans problème.

Quelqu'un pourrait-il m'aider et m'indiquer la bonne démarche ?

Merci d'avance pour vos réponses