bonjour,
je voudrais bien savoir comment remplir un combobox richfaces a partir d'une table base de données oracle en utilisant richfaces 3.3 et hibernate sous eclipse?
Cordialement
Elamarti
bonjour,
je voudrais bien savoir comment remplir un combobox richfaces a partir d'une table base de données oracle en utilisant richfaces 3.3 et hibernate sous eclipse?
Cordialement
Elamarti
Pour récupérer la liste avec hibernate, il faut regarder les tutoriels et faq hibernate/JPA.
Pour la combo box, tu peux utiliser une liste de SelectItems construite à partir de ta liste d'objets.
Articles: Richfaces - JBosstools pour JSF.
merci pour ta réponse mais est ce que tu peux m'expliquer plus en detail car je suis encore débutant?
Amicalement
pour bien expliquer mon problem voici le code source ainsi et que l'erreur affiché :
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 <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="richfaces"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="beans.DroitUser"%> <%@page import="beans.Product"%> <%@page import="beans.Voucher"%> <%@page import="manager.HibernateUtil"%> <%@page import="manager.HibernateManager"%> <%@page import="java.util.List"%> <html> <head> <title></title> </head> <body> <f:view> <richfaces:panel> <%! HibernateManager hbm = new HibernateManager(); %> <rich:comboBox defaultLabel="Enter some value" value="#{beans.Product}"> <t:selectItems value="#{hbm.getAllProducts()}" var="list" itemLabel="#{list.getPrdName()}" itemValue="#{list.getPrdName()}" /> </rich:comboBox> </richfaces:panel> </f:view> </body> </html>
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 org.apache.jasper.JasperException: /facture.jsp(25,41) #{...} is not allowed in template text org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102) org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:713) org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:958) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411) org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:871) org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411) org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:871) org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411) org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417) org.apache.jasper.compiler.Node$Root.accept(Node.java:495) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361) org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1775) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:183) org.apache.jasper.compiler.Compiler.compile(Compiler.java:332) org.apache.jasper.compiler.Compiler.compile(Compiler.java:312) org.apache.jasper.compiler.Compiler.compile(Compiler.java:299) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:410) com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:468) com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140) org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100) org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176) com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178) org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388) org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
Essaies ça :
L'EL (expression language) JSF "#{hbm.allProducts}" appellera le getter de l'attribut "allProducts" du controller "hbm".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 <rich:comboBox defaultLabel="Enter some value" value="#{beans.Product}"> <t:selectItems value="#{hbm.allProducts}" var="list" itemLabel="#{list.prdName}" itemValue="#{list.prdName}" /> </rich:comboBox>
toujours le meme problemeet en plus il reconnait pas le tag <t:selectitems /> mais plutot <f:selectitems /> et aussi ne reconnait pas le tag <rich:combobox/> par contre <richfaces:combobox /> il l'accepte
Ne met pas de majuscule : beans.product au lieu de beans.Product
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <rich:comboBox defaultLabel="Enter some value" value="#{beans.product}"> <t:selectItems value="#{hbm.allProducts}" var="list" itemLabel="#{list.prdName}" itemValue="#{list.prdName}" /> </rich:comboBox>
Vérifies la présence de la méthode setProduct dans ton controller "beans" et getAllProducts dans le controller "hbm". D'ailleurs peux-tu me donner leur contenu?
FAQ pour les listes déroulantes JSF (la logique est la même pour rich:comboBox)
voici le code de la méthode getAllProduct dans HibernateManager :
et voici le code de mon bean Product :
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 public List<Product> getAllProducts() { System.out.println("Entrer getAllProducts()"); session = HibernateUtil.currentSession(); try { listProduct = session.createQuery( "from Product prd order by prd.prdCode").list(); } catch (ExceptionInInitializerError e) { System.out.println("getAllProduct() ne marche pas : " + e.getMessage()); } for (int i = 0; i < listProduct.size(); i++) { System.out.println("listProduct.get(" + i + ") : " + listProduct.get(i).getPrdName()); System.out.println("listProduct.get(" + i + ") : " + listProduct.get(i).getOperator()); } //HibernateUtil.closeSession(); return listProduct; }
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
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
252 package beans; // Generated 16 juil. 2009 17:59:54 by Hibernate Tools 3.2.2.GA import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.Set; /** * Product generated by hbm2java */ public class Product implements java.io.Serializable { /** * */ /*****************Default Serial****************/ private static long serialVersionUID = 1L; /***********************************************/ private BigDecimal prdCode; private Operator operator; private BigDecimal prdAmount; private String prdType; private Date prdDateCreate; private Date prdDateMENV; private Date prdExpiryDate; private String prdName; private Set<WhsOrderRecord> whsOrderRecords = new HashSet<WhsOrderRecord>(0); private Set<Voucher> vouchers = new HashSet<Voucher>(0); private Set<MerOrderRecord> merOrderRecords = new HashSet<MerOrderRecord>(0); public Product() { } public Product(BigDecimal prdCode, Operator operator) { this.prdCode = prdCode; this.operator = operator; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, Set<WhsOrderRecord> whsOrderRecords, Set<Voucher> vouchers, Set<MerOrderRecord> merOrderRecords) { this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.whsOrderRecords = whsOrderRecords; this.vouchers = vouchers; this.merOrderRecords = merOrderRecords; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, String prdType, Date prdDateCreate, Date prdDateMENV, Date prdExpiryDate, String prdName) { super(); this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.prdType = prdType; this.prdDateCreate = prdDateCreate; this.prdDateMENV = prdDateMENV; this.prdExpiryDate = prdExpiryDate; this.prdName = prdName; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, String prdType, Date prdDateCreate, Date prdDateMENV, Date prdExpiryDate) { super(); this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.prdType = prdType; this.prdDateCreate = prdDateCreate; this.prdDateMENV = prdDateMENV; this.prdExpiryDate = prdExpiryDate; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount) { this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; } public BigDecimal getPrdCode() { return this.prdCode; } public void setPrdCode(BigDecimal prdCode) { this.prdCode = prdCode; } public Operator getOperator() { return this.operator; } public void setOperator(Operator operator) { this.operator = operator; } public BigDecimal getPrdAmount() { return this.prdAmount; } public void setPrdAmount(BigDecimal prdAmount) { this.prdAmount = prdAmount; } public Set<WhsOrderRecord> getWhsOrderRecords() { return this.whsOrderRecords; } public void setWhsOrderRecords(Set<WhsOrderRecord> whsOrderRecords) { this.whsOrderRecords = whsOrderRecords; } public Set<Voucher> getVouchers() { return this.vouchers; } public void setVouchers(Set<Voucher> vouchers) { this.vouchers = vouchers; } public Set<MerOrderRecord> getMerOrderRecords() { return this.merOrderRecords; } public void setMerOrderRecords(Set<MerOrderRecord> merOrderRecords) { this.merOrderRecords = merOrderRecords; } public String getPrdType() { return prdType; } public void setPrdType(String prdType) { this.prdType = prdType; } public Date getPrdDateCreate() { return prdDateCreate; } public String getPrdDateCreateFormat(String format){ //format = "dd/MM/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdDateCreate); return reportDate; } public void setPrdDateCreate(Date prdDateCreate) { this.prdDateCreate = prdDateCreate; } public Date getPrdDateMENV() { return prdDateMENV; } public String getPrdDateMENVFormat(String format){ //format = "MM/dd/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdDateMENV); return reportDate; } public void setPrdDateMENV(Date prdDateMENV) { this.prdDateMENV = prdDateMENV; } public Date getPrdExpiryDate() { return prdExpiryDate; } public String getPrdExpiryDateFormat(String format){ //format = "dd/MM/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdExpiryDate); return reportDate; } public void setPrdExpiryDate(Date prdExpiryDate) { this.prdExpiryDate = prdExpiryDate; } public static long getSerialVersionUID() { return serialVersionUID; } public String getPrdName() { return prdName; } public void setPrdName(String prdName) { this.prdName = prdName; } public String[] getManage(){ return new String[]{"Ajouter Produit", "Consulter Produit"}; } public String[][] getAttributes(){ //il faut modifier dans la servlet pour l'einsertion il y a plus maitenant d'objet ProductId String [][]r = {{"Code", "Nom", "Operateur","Montant","Type de Produit","Date de creation","Date du produit","Date d'expiration"}, {"text", "text", "select", "text", "text", "text", "text", "text"}, {"prdCode","prdName", "operator","prdAmount","prdType","prdDateCreate","prdDateMENV","prdExpiryDate"}, {"number","text","text", "number","text","date","date","date"}, {"22","22", "22", "22", "22", "22", "22", "22"}}; return r; } public String[][] getAttributesEng(){ //il faut modifier dans la servlet pour l'einsertion il y a plus maitenant d'objet ProductId String [][]r = {{"Code", "Product Name", "Operator","Product Amount","Product Type","Product Creation date","Sales Date","Expiration Date"}, {"text", "text", "select", "text", "text", "text", "text", "text"}, {"prdCode","prdName", "operator","prdAmount","prdType","prdDateCreate","prdDateMENV","prdExpiryDate"}, {"number","text","text", "number","text","date","date","date"}, {"22","22", "22", "22", "22", "22", "22", "22"}}; return r; } public void setSerialVersionUID(long serialVersionUID) { this.serialVersionUID = serialVersionUID; } }
As-tu vérifié la présence de la méthode setProduct dans ton controller "beans"?
Attention, "product" représente le nom d'une variable (et pas un type) du controller "beans"! As-tu un attribut :
Code : Sélectionner tout - Visualiser dans une fenêtre à part value="#{beans.product}"
dans ton code? As-tu implémenté son getter et son setter?
Code : Sélectionner tout - Visualiser dans une fenêtre à part Product product:
j'ai pas bien compris ce que tu voulais dire .est ce que tu peux te connecter dans le salon du chat de developpez?
Amicalement
Je viens de comprendre ce que tu as fait : dans l'attribut "value" de la balise rich:comboBox tu as mis le chemin de ton Bean. Attention, "value" doit contenir une variable de ton controller.
Tu dois avoir un truc qui ressemble à ça :
Avec plutôt :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 public class TonController { Product product = new Product(); public void setProduct(Product p){ product = p; } public Product getProduct(){ return product; } }
Par contre, dans ta variable product, tu n'auras que l'id et pas l'objet complet. Si tu veux l'objet complet il faudra faire une requête en base grâce à l'id ainsi obtenu.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <rich:comboBox defaultLabel="Enter some value" value="#{nomDuController.product.id}"> <t:selectItems value="#{hbm.allProducts}" var="list" itemLabel="#{list.prdName}" itemValue="#{list.id}" /> </rich:comboBox>
méme probleme mon ami , je crois que mon eclipse ne connait pas le tag <rich:combobox/> alors quoi faire a ton avis si c'est le cas?![]()
Si tu n'as pas installé les JAR pour RichFaces c'est normal. Utilises le composant JSF standard :
Et reprends tout ce qu'on a dit.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <h:selectOneMenu value="#{hbm.product.id}"> <f:selectItems value="#{hbm.allProducts}"/> </h:selectOneMenu>
Je crois que je devrais te montrer tout mon code ainsi que les jar que j'ai ajouté a mon buildpath :
1/les jars ajouté sont les suivants :
richfaces-api-3.3.2.SR1
richfaces-impl-3.3.2.SR1
richfaces-ui-3.3.2.SR1
activation
antlr-2.7.4
antlr-2.7.6
cglib-full-2.0.2
common-annotations
commons-beanutils
commons-beanutils-1.8.0
commons-collections
commons-collections-2.1.1
commons-collections-3.1
commons-collections-3.2.1
commons-dbcp-1.2.2
commons-digester
commons-digester-1.7
commons-javaflow-20060411
commons-logging
commons-logging-1.0.4
commons-logging-1.1
commons-pool-1.3
commons-vfs-1.0
dom4j-1.5.2
dom4j-1.6.1
dsn
ehcache-1.1
hibernate3
hibernate-entitymanager
hibernate-testing
hibernate-validator-3.0.0.ga
imap
iText-2.1.0
iText-2.1.5
iTextAsian
jasperreports-3.6.1
javassist-3.4.GA
jcommon-1.0.16
jdom
jdt-compiler-3.1.1
jfreechart-1.0.13
jfreechart-1.0.13-experimental
jfreechart-1.0.13-swt
jsf-api
jsf-impl
jsf-tlds
jstl
jta
jta-1.1
junit
log4j-1.2.9
ojdbc14
poi-3.2-FINAL-20081019
pop3
servlet
smtp
standard
swtgraphics2d
2/le fichier faces-config.xml:
3/web.xml :
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 <?xml version="1.0" encoding="UTF-8"?> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" 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"> <managed-bean> <managed-bean-name>ajaxbean</managed-bean-name> <managed-bean-class>beans.Ajaxbean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>value</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> </managed-bean> <managed-bean> <managed-bean-name>MB</managed-bean-name> <managed-bean-class>beans.MB</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>userBean</managed-bean-name> <managed-bean-class>beans.UserBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>name</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>age</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>job</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> </managed-bean> <managed-bean> <managed-bean-name>validationBean</managed-bean-name> <managed-bean-class>beans.ValidationBean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>name</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>email</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>age</property-name> <property-class>java.lang.Integer</property-class> <value/> </managed-property> </managed-bean> <managed-bean> <managed-bean-name>product</managed-bean-name> <managed-bean-class>beans.Product</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>operator</property-name> <property-class>beans.Operator</property-class> <value/> </managed-property> <managed-property> <property-name>prdAmount</property-name> <property-class>java.math.BigDecimal</property-class> <value/> </managed-property> <managed-property> <property-name>prdCode</property-name> <property-class>java.math.BigDecimal</property-class> <value/> </managed-property> <managed-property> <property-name>prdDateCreate</property-name> <property-class>java.util.Date</property-class> <value/> </managed-property> <managed-property> <property-name>prdDateCreateFormat</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>prdDateMENV</property-name> <property-class>java.util.Date</property-class> <value/> </managed-property> <managed-property> <property-name>prdDateMENVFormat</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>prdExpiryDate</property-name> <property-class>java.util.Date</property-class> <value/> </managed-property> <managed-property> <property-name>prdExpiryDateFormat</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>prdName</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>prdType</property-name> <property-class>java.lang.String</property-class> <value/> </managed-property> <managed-property> <property-name>serialVersionUID</property-name> <property-class>long</property-class> <value/> </managed-property> <managed-property> <property-name>vouchers</property-name> <property-class>java.util.Set</property-class> <value/> </managed-property> <managed-property> <property-name>whsOrderRecords</property-name> <property-class>java.util.Set</property-class> <value/> </managed-property> </managed-bean> </faces-config>
4/Controller.java : comme tu m'as dit de le faire :
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 <?xml version="1.0"?> <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"> <display-name>jsftestrichfaces</display-name> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <!--<context-param> <param-name>org.ajax4jsf.SKIN</param-name> <param-value>classic</param-value> </context-param> --> <context-param> <param-name>org.richfaces.SKIN</param-name> <param-value>ruby</param-value> </context-param> <filter> <display-name>Ajax4jsf Filter</display-name> <filter-name>ajax4jsf</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>ajax4jsf</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
5/Le bean Product.java:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package controller; import beans.Product; public class Controller { private Product product = new Product(); public void setProduct(Product p){ product = p; } public Product getProduct(){ return product; } }
6/La méthode getAllProduct de la classe HibernateManager:
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
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
252
253
254
255
256
257
258
259
260 package beans; // Generated 16 juil. 2009 17:59:54 by Hibernate Tools 3.2.2.GA import java.math.BigDecimal; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashSet; import java.util.Set; /** * Product generated by hbm2java */ public class Product implements java.io.Serializable { /** * */ /*****************Default Serial****************/ private static long serialVersionUID = 1L; /***********************************************/ private BigDecimal prdCode; private Operator operator; private BigDecimal prdAmount; private String prdType; private Date prdDateCreate; private Date prdDateMENV; private Date prdExpiryDate; private String prdName; private Set<WhsOrderRecord> whsOrderRecords = new HashSet<WhsOrderRecord>(0); private Set<Voucher> vouchers = new HashSet<Voucher>(0); private Set<MerOrderRecord> merOrderRecords = new HashSet<MerOrderRecord>(0); private Product product; public Product() { } public Product(BigDecimal prdCode, Operator operator) { this.prdCode = prdCode; this.operator = operator; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, Set<WhsOrderRecord> whsOrderRecords, Set<Voucher> vouchers, Set<MerOrderRecord> merOrderRecords) { this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.whsOrderRecords = whsOrderRecords; this.vouchers = vouchers; this.merOrderRecords = merOrderRecords; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, String prdType, Date prdDateCreate, Date prdDateMENV, Date prdExpiryDate, String prdName) { super(); this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.prdType = prdType; this.prdDateCreate = prdDateCreate; this.prdDateMENV = prdDateMENV; this.prdExpiryDate = prdExpiryDate; this.prdName = prdName; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount, String prdType, Date prdDateCreate, Date prdDateMENV, Date prdExpiryDate) { super(); this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; this.prdType = prdType; this.prdDateCreate = prdDateCreate; this.prdDateMENV = prdDateMENV; this.prdExpiryDate = prdExpiryDate; } public Product(BigDecimal prdCode, Operator operator, BigDecimal prdAmount) { this.prdCode = prdCode; this.operator = operator; this.prdAmount = prdAmount; } public BigDecimal getPrdCode() { return this.prdCode; } public void setPrdCode(BigDecimal prdCode) { this.prdCode = prdCode; } public Operator getOperator() { return this.operator; } public void setOperator(Operator operator) { this.operator = operator; } public BigDecimal getPrdAmount() { return this.prdAmount; } public void setPrdAmount(BigDecimal prdAmount) { this.prdAmount = prdAmount; } public Set<WhsOrderRecord> getWhsOrderRecords() { return this.whsOrderRecords; } public void setWhsOrderRecords(Set<WhsOrderRecord> whsOrderRecords) { this.whsOrderRecords = whsOrderRecords; } public Set<Voucher> getVouchers() { return this.vouchers; } public void setVouchers(Set<Voucher> vouchers) { this.vouchers = vouchers; } public Set<MerOrderRecord> getMerOrderRecords() { return this.merOrderRecords; } public void setMerOrderRecords(Set<MerOrderRecord> merOrderRecords) { this.merOrderRecords = merOrderRecords; } public String getPrdType() { return prdType; } public void setPrdType(String prdType) { this.prdType = prdType; } public Date getPrdDateCreate() { return prdDateCreate; } public String getPrdDateCreateFormat(String format){ //format = "dd/MM/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdDateCreate); return reportDate; } public void setPrdDateCreate(Date prdDateCreate) { this.prdDateCreate = prdDateCreate; } public Date getPrdDateMENV() { return prdDateMENV; } public String getPrdDateMENVFormat(String format){ //format = "MM/dd/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdDateMENV); return reportDate; } public void setPrdDateMENV(Date prdDateMENV) { this.prdDateMENV = prdDateMENV; } public Date getPrdExpiryDate() { return prdExpiryDate; } public String getPrdExpiryDateFormat(String format){ //format = "dd/MM/yyyy"; DateFormat df = new SimpleDateFormat(format); String reportDate = df.format(prdExpiryDate); return reportDate; } public void setPrdExpiryDate(Date prdExpiryDate) { this.prdExpiryDate = prdExpiryDate; } public static long getSerialVersionUID() { return serialVersionUID; } public String getPrdName() { return prdName; } public void setPrdName(String prdName) { this.prdName = prdName; } public String[] getManage(){ return new String[]{"Ajouter Produit", "Consulter Produit"}; } public String[][] getAttributes(){ //il faut modifier dans la servlet pour l'einsertion il y a plus maitenant d'objet ProductId String [][]r = {{"Code", "Nom", "Operateur","Montant","Type de Produit","Date de creation","Date du produit","Date d'expiration"}, {"text", "text", "select", "text", "text", "text", "text", "text"}, {"prdCode","prdName", "operator","prdAmount","prdType","prdDateCreate","prdDateMENV","prdExpiryDate"}, {"number","text","text", "number","text","date","date","date"}, {"22","22", "22", "22", "22", "22", "22", "22"}}; return r; } public String[][] getAttributesEng(){ //il faut modifier dans la servlet pour l'einsertion il y a plus maitenant d'objet ProductId String [][]r = {{"Code", "Product Name", "Operator","Product Amount","Product Type","Product Creation date","Sales Date","Expiration Date"}, {"text", "text", "select", "text", "text", "text", "text", "text"}, {"prdCode","prdName", "operator","prdAmount","prdType","prdDateCreate","prdDateMENV","prdExpiryDate"}, {"number","text","text", "number","text","date","date","date"}, {"22","22", "22", "22", "22", "22", "22", "22"}}; return r; } public void setSerialVersionUID(long serialVersionUID) { this.serialVersionUID = serialVersionUID; } public void setProduct(Product product) { this.product = product; } public Product getProduct() { return product; } }
3/enfin la page jsp:
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 public List<Product> getAllProducts() { System.out.println("Entrer getAllProducts()"); session = HibernateUtil.currentSession(); try { listProduct = session.createQuery( "from Product prd order by prd.prdCode").list(); } catch (ExceptionInInitializerError e) { System.out.println("getAllProduct() ne marche pas : " + e.getMessage()); } for (int i = 0; i < listProduct.size(); i++) { System.out.println("listProduct.get(" + i + ") : " + listProduct.get(i).getPrdName()); System.out.println("listProduct.get(" + i + ") : " + listProduct.get(i).getOperator()); } //HibernateUtil.closeSession(); return listProduct; }
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 <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="richfaces"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="beans.DroitUser"%> <%@page import="beans.Product"%> <%@page import="beans.Voucher"%> <%@page import="manager.HibernateUtil"%> <%@page import="manager.HibernateManager"%> <%@page import="controller.Controller"%> <%@page import="java.util.List"%> <html> <head> <title></title> </head> <body> <f:view> <%! HibernateManager hbm = new HibernateManager(); %> <richfaces:panel> <rich:comboBox defaultLabel="Enter some value" value="#{Controller.product.prdCode}"> <t:selectItems value="#{hbm.allProducts}" var="list" itemLabel="#{list.prdName}" itemValue="#{list.prdCode}" /> </rich:comboBox> </richfaces:panel> </f:view> </body> </html>
Je ne peux pas t'en dire plus, pas trop de temps en ce moment. Cherches sur internet des exemples d'utilisation de la balise RichFaces ou du composant standard (SelectOneMenu). Regardes aussi dans la FAQ.
Discussion traitant de la balise SelectOneMenu.
Bon courage
Les réponses à tes tags inconnus sont là :
Code : Sélectionner tout - Visualiser dans une fenêtre à part toujours le meme probleme et en plus il reconnait pas le tag <t:selectitems /> mais plutot <f:selectitems /> et aussi ne reconnait pas le tag <rich:combobox/> par contre <richfaces:combobox />
c'est toi même qui as demandé ces différents préfixes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="richfaces"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>![]()
Partager