Bonjour,

J'aimerais savoir comment passer un objet d'un contrôleur à un autre.

En fait, j'ai une page avec un formulaire de recherche.
J'aimerais récupérer les informations saisies, effectuer ma recherche et envoyer les résultats à ma jsp qui les afficherait ...

Pour le moment, c'est le même contrôleur qui fait tout ...
Merci pour votre aide


Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
<!-- Pour la recherche unitaire -->
<bean id="rechercheUnitaireController" class="RechercheUnitaireController">
	<property name="domainService" ref="domainService" />
	<property name="commandName" value="command" />
	<property name="commandClass" value="RechercheUnitaire" />
	<property name="formView" value="secure/recherche-unitaire" />
	<property name="validator" ref="rechercheUnitaireValidator" />
</bean>
 
<entry key="/secure/recherche-unitaire.html" value-ref="rechercheUnitaireController" />
<entry key="/secure/resultat-recherche-unitaire.html" value-ref="rechercheUnitaireController" />
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
 
 
import RechercheUnitaire;
import Article;
import Client;
import Installation;
import Site;
import DomainService;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
 
public class RechercheUnitaireController extends SimpleFormController {
	private Log logger = LogFactory.getLog(RechercheUnitaire.class);
	private DomainService domainService;
 
	public void setDomainService(DomainService domainService) {
		this.domainService = domainService;
	}
 
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
		ModelAndView mav = new ModelAndView("/secure/resultat-recherche-unitaire");
		// On récupère les critères de recherche
		RechercheUnitaire ru = (RechercheUnitaire)command;
		logger.info("RechUni : " + ru.getIdent() + ru.getNom_client() + ru.getSiren());
		// On effectue la recherche selon le type d'objets recherché
		switch(ru.getType()){
		case RechercheUnitaire.CLIENT:
			List<Client> clients = domainService.rechercheClients(ru.getIdent(), ru.getNom_client(), ru.getSiren());
			mav.addObject("resultatsRecherche", clients);
			break;
		case RechercheUnitaire.SITE:
			List<Site> sites = domainService.rechercheSites(ru.getIdeta(), ru.getNom_site(), ru.getSiret());
			mav.addObject("resultatsRecherche", sites);	
			break;
		case RechercheUnitaire.INSTALLATION:
			List<Installation> installations = domainService.rechercheInstallations(ru.getRef(), ru.getLibelle());
			mav.addObject("resultatsRecherche", installations);
			break;
		case RechercheUnitaire.EQUIPEMENT:
		default:
			List<Client> articles = domainService.rechercheArticles(ru.getNumeroSerie());
			mav.addObject("resultatsRecherche", articles);
			break;
		}
		mav.addObject("type", ru.getType());
		return mav;
	}
 
	protected Object formBackingObject(HttpServletRequest request) throws Exception {
		logger.info("formBackingObject rech uni");
		return new RechercheUnitaire();
	}
}