IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Web Java Discussion :

Formulaire avec redirection sur lui-meme


Sujet :

Spring Web Java

  1. #1
    Membre actif
    Inscrit en
    Décembre 2003
    Messages
    491
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 491
    Points : 245
    Points
    245
    Par défaut Formulaire avec redirection sur lui-meme
    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 :
    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";
        }
    	*/
    }
    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
     
    <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>

  2. #2
    Membre actif
    Inscrit en
    Décembre 2003
    Messages
    491
    Détails du profil
    Informations forums :
    Inscription : Décembre 2003
    Messages : 491
    Points : 245
    Points
    245
    Par défaut
    J'ai pu résoudre mon problème avec les articles suivants :

    // Spring MVC - Flash Attributes
    // https://dzone.com/articles/spring-mvc-flash-attributes
    // https://www.javacodegeeks.com/2012/0...ttributes.html
    // https://www.intertech.com/Blog/under...on-attributes/
    // http://javabeat.net/flash-attributes-in-spring-mvc-3-1/

    Je n'en ai retenu que les Flash Attributes

    J'espère que cela sera utile à quequ'un

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DOM] Formulaire et redirection sur annulation
    Par mathieugamin dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 25/04/2007, 10h48
  2. formulaire avec redirection
    Par furth dans le forum Langage
    Réponses: 3
    Dernier message: 13/10/2006, 17h02
  3. [Access] Requête (avec AND) sur 1 meme champ d'une table
    Par jeje22 dans le forum Langage SQL
    Réponses: 3
    Dernier message: 11/09/2006, 22h59
  4. pb avec lien sur la meme page
    Par kivoch dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 13/01/2006, 16h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo