Bonjour,
Je fais un formulaire avec une redirection à travers un submit sur lui-meme et je n'arrive pas
à recharger les données préparées dans le controlleur.
Pour le contexte, j'ai une liste d'entrées en banque de données a afficher à l'écran.
Sur ma .jsp j'ai des select box chargés avec des listes extraites de la banque de données pour pouvoir faire des tris
sur l'affichage.
Les données que j'extrais des selects sont sauvées dans une instance de la classe POJO representée dans la liste et ces données
reste accessibles.
Le contenu des listes déclarées dans le controlleur est par contre perdu.
Est-ce qu'il ya a moyen de récupérer ces valeurs?
Voir ci-dessous, le Ici un essai : flight.depAirpCode marche très bien mais les listes : SV_depAirpCodeList, SV_arrAirpCodeList, SV_colFromList, SV_colUntilList sont perdues.
Merci pour votre aide
Ici mon controller :
Ici ma .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
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 <body> Ici bientot la liste <h2 class=cssTitle>Flights' Filters Criterias </h2> <div> <form:form method="post" commandName="flight"> <table class=cssLayouttable> <tr> <td>Orig.</td> <td> <form:select path="depAirpCode"> <form:options items="${SV_depAirpCodeList}" /> </form:select> </td> <td><form:label path="arrAirpCode">Dest. </form:label></td> <td> <form:select path="arrAirpCode"> <form:options items="${SV_arrAirpCodeList}" /> </form:select> </td> <td><form:label path="colFrom">From</form:label></td> <td> <form:select path="colFrom"> <form:options items="${SV_colFromList}" /> </form:select> </td> <td><form:label path="colUntil">Until</form:label></td> <td> <form:select path="colUntil"> <form:options items="${SV_colUntilList}" /> </form:select> </td> <td></td> <td> <input type = "submit" value = "submit"/> </td> </tr> </table> </form:form> </div> Ici un essai : ${flight.depAirpCode} </body> /* @Controller public class UserController { @Autowired private UserDAO userDAO; @RequestMapping("user_list") public void userList() { userDAO.performSeveralQueries(); } @RequestMapping("/jsp/local_db_flight_list") */ @Controller @RequestMapping("local_db_flight_list") public class FlightController { @Autowired private FlightDAO flightDao; private List<Flight>allFlightList; public TreeSet<String>allDepAirp; private TreeSet<String>allArrAirp; private TreeSet<String>allDateFrom; private TreeSet<String>allDateUntil; public FlightController() { } @RequestMapping("/jsp/local_db_flight_list") private void initAllFlightList() { allFlightList = flightDao.listAllFlight(); if (allFlightList != null) { allDepAirp = flightDao.retrieveListAllDepAirport(); allArrAirp = flightDao.retrieveListAllDepAirport(); allDateFrom = flightDao.retrieveListAllDateFrom(); allDateUntil = flightDao.retrieveListAllDateUntil(); // allDepDate System.out.println("Nof Items, allFlightList : " + allFlightList.size()); } else { System.out.println("Badaboum"); } } //*********************************************************************** // GUI only, Add List to GUI-Widgets @RequestMapping(method = RequestMethod.GET) public ModelAndView showFlightForm() { initAllFlightList(); Flight flight = new Flight(); // Add the command object to the modelview ModelAndView mv = new ModelAndView("flight"); mv.addObject("flight", flight); mv.addObject("SV_depAirpCodeList", allDepAirp); mv.addObject("SV_arrAirpCodeList", allArrAirp); mv.addObject("SV_colFromList", allDateFrom); mv.addObject("SV_colUntilList", allDateUntil); return mv; } @RequestMapping(method = RequestMethod.POST) public String submitForm(Model model, Flight flight, BindingResult result) { return "flight"; // return "success"; } /* @RequestMapping(method = RequestMethod.GET) public void viewFilteredFlightList() { System.out.println("Ici la methode viewFilteredFlightList"); // return "flight"; } */ }
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 <body> Ici bientot la liste <h2 class=cssTitle>Flights' Filters Criterias </h2> <div> <form:form method="post" commandName="flight"> <table class=cssLayouttable> <tr> <td>Orig.</td> <td> <form:select path="depAirpCode"> <form:options items="${SV_depAirpCodeList}" /> </form:select> </td> <td><form:label path="arrAirpCode">Dest. </form:label></td> <td> <form:select path="arrAirpCode"> <form:options items="${SV_arrAirpCodeList}" /> </form:select> </td> <td><form:label path="colFrom">From</form:label></td> <td> <form:select path="colFrom"> <form:options items="${SV_colFromList}" /> </form:select> </td> <td><form:label path="colUntil">Until</form:label></td> <td> <form:select path="colUntil"> <form:options items="${SV_colUntilList}" /> </form:select> </td> <td></td> <td> <input type = "submit" value = "submit"/> </td> </tr> </table> </form:form> </div> Ici un essai : ${flight.depAirpCode} </body>
Partager