Salut à tous, voilà j'ai un petit problème avec mes dates !
Lorsque j'essaie de retourner une date, l'appli me met cette erreur
Illegal pattern character 'f'
Voila mn bean
et ma page XHTML
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 package view; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; import javax.annotation.PostConstruct; import javax.enterprise.context.ConversationScoped; import javax.enterprise.inject.Produces; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; import entities.*; import service.ServiceProvider;; @ConversationScoped @Named("editService") public class ServiceBean implements Serializable { private static final long serialVersionUID = -1089153575165747678L; @Inject private FacesContext facesContext; @Inject private ServiceProvider sp; private String dateDebChoix; private String dateFinChoisi; private Service Service; public String getDateFinChoisi() { return dateFinChoisi; } public void setDateFinChoisi(String dateFinChoisi) { this.dateFinChoisi = dateFinChoisi; } public String getDateDebChoix() { return dateDebChoix; } public void setDateDebChoix(String dateDebChoix) { this.dateDebChoix = dateDebChoix; } @PostConstruct public void init() { if (Service == null) { String ServiceId = (String) facesContext.getExternalContext() .getRequestParameterMap().get("id"); if (ServiceId != null) { try { Service = sp.getService(Integer.parseInt(ServiceId)); } catch (NumberFormatException e) { facesContext.addMessage(null, new FacesMessage(ServiceId + " n'est pas un n° de service valide")); } /*catch (AgentNotFoundExcsption e) { facesContext.addMessage(null, new FacesMessage("service " + ServiceId + " non trouvé")); }*/ } } } @Produces @Named public Service getCurrentService() { return Service; } public static Date stringToDate(String sDate, String sFormat) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(sFormat); return sdf.parse(sDate); } public void save() { try { System.out.println("Date Début=="+this.getDateDebChoix()); System.out.println("Date Fin=="+this.getDateFinChoisi()); Date dateChoisidebut = stringToDate(dateDebChoix,"full"); Date dateChoisifin = stringToDate(dateFinChoisi,"full"); Service.setDateDeb_se(dateChoisidebut); Service.setDateFin_se(dateChoisifin); sp.saveService(Service); sp.flush(); } catch (Exception e) { facesContext.addMessage(null, new FacesMessage(e.getMessage())); } finally { sp.clear(); } } }
Est-ce que l'erreur proviendrait de mon "full" ?!
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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"> <f:metadata> <f:viewParam name="id" value="#{currentService.code_se}"/> </f:metadata> <ui:composition template="/WEB-INF/templates/template.xhtml"> <ui:define name="header"> <h1> <h:outputText value="#{msgs['service.titreE']}" /> </h1> </ui:define> <ui:define name="content"> <h:form> <h:messages /> <h:outputText value="#{msgs['service.nom']}" /> <h:inputText value="#{currentService.lib_se}" /> <br/> <h:outputText value="#{msgs['service.des']}" /> <h:inputText value="#{currentService.des_se}" /> <br/> <h:outputText value="#{msgs['service.dateD']}" /> <h:inputText value="#{editService.dateDebChoix}" /> <br/> <h:outputText value="#{msgs['service.dateF']}" /> <h:inputText value="#{editService.dateFinChoisi}" /> <br/> <h:commandButton value="Enregistrer" action="#{editService.save}" > <f:param name="id" value="#{currentService.code_se}"/> </h:commandButton> </h:form> </ui:define> </ui:composition> </html>
Merci de votre attention !
Ps : j'utilise les plug-in JSF, JPA, CDI
Bonne journée et futur bon week end !
Partager