I am pretty new in Spring MVC and I have the following problem.
Into an home() controller method defined into a class named **HomeController I retrieve an object using a service. This object have to be put as Session Attribute so it can be used from other methods in other controller classes.
So I have done in this way:
@Controller
@SessionAttributes({"progettoSelezionato"})
@PropertySource("classpath:messages.properties")
public class HomeController {
private static final Logger logger = Logger.getLogger(LoginController.class);
private @Autowired HomeService homeService;
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Model model) {
List<Tid023Intervento> listaInterventi = homeService.getListaInterventiRUP(18);
model.addAttribute("progettoSelezionato", listaInterventi.get(0));
model.addAttribute("listaProgettiRUP", listaInterventi);//TODO
return "home";
}
}
As you can see I have used this annotation on the class level:
@SessionAttributes({"progettoSelezionato"})
and then I put this object by:
model.addAttribute("progettoSelezionato", listaInterventi.get(0));
I am not sure that this is correct because, from what I know, this put the retrieved listaInterventi.get(0) object into the model with the voice progettoSelezionato. So I am absolutly not sure that it is putted as SessionAttributes.
Then, after that this object is putted as SessionAttriibute I have to retrieve and use if from a gestioneDatiContabiliEnte() method defined into another controller class, so I am doing in this way:
@Controller
@SessionAttributes({"progettoSelezionato"})
@PropertySource("classpath:messages.properties")
public class GestioneDatiContabiliEnteController {
private static final Logger logger = Logger.getLogger(LoginController.class);
@RequestMapping(value = "/gestioneDatiContabiliEnte", method = RequestMethod.GET)
public String gestioneDatiContabiliEnte(Model model) {
System.out.println("INTO gestioneDatiContabiliEnte()");
System.out.println("PROGETTO SELEZIONATO: " + progettoSelezionato);
return "gestioneDatiContabiliEnte/gestioneDatiContabiliEnte";
}
}
But it seems can't work because Eclipse sign me error on this line:
System.out.println("PROGETTO SELEZIONATO: " + progettoSelezionato);
The error is: progettoSelezionato cannot be resolved to a variable.
How can I correctly put the listaInterventi.get(0) as SessionAttribute into my HomeController? And how can I retrieve and use it into the gestioneDatiContabiliEnte() method defined into my GestioneDatiContabiliEnteController class?