[Spring MVC] Formulaire Spring MVC disparaît de la HttpSession
Bonsoir à tous,
voici mon petit problème :
je dispose d'une formulaire permettant d'entrer des critères de recherches. Les résultats de la recherche s'affichent sur la même page que le formulaire. Jusque là tout va bien :-)
Lorsque l'utilisateur clique sur un des résultats de la recherche, une nouvelle page s'affiche (détail). Un bouton permet de revenir de revenir au résultat de la recherche. Et là ... les critères de recherche entrés par l'utilisateur ont disparu...
Je n'y comprend rien car voici la déclaration du controleur dans le fichier .xml :
Code:
1 2 3 4 5 6 7
| <bean id="searchBooksController" class="com.frontend.controller.formcontroller.SearchBookController">
<property name="sessionForm" value="true"/>
<property name="commandClass"><value>com.core.criteria.BookCriteria</value></property>
<property name="formView"><value>searchBooks</value></property>
<property name="successView"><value>searchBooks</value></property>
<property name="commandName"><value>criteria</value></property>
</bean> |
Le formulaire est pourtant en session or ses attributs sont nuls
Quelqu'un aurait-il une idée de ce qu'il se passe ?
Merci d'avance à tous ceux qui auront tenté ou réussi à m'aider.
Coyote
Voici le code des controllers
Oui bien sur :D
Voici le code du controlleur :
Code:
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
|
public class SearchBookController extends AbstractFormController {
private final static int MAX_LATEST_BOOKS = 10;
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
Map references = super.referenceData(request, command, errors);
// retrieve categories in order to display them in a comb
request.getSession().setAttribute("categories", getServiceLocator().getBiblioService().findAllCategories());
BookCriteria criteria = (BookCriteria) command;
List<Book> books = getServiceLocator().getBiblioService().findBooksByCriteria(criteria);
references.put("books", books);
return references;
}
protected boolean isFormChangeRequest(HttpServletRequest request) {
// The form should always loop back to itself
return true;
}
} |
Et enfin le code de l'ancêtre :
Code:
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
|
public class AbstractSimpleFormController extends SimpleFormController implements BaseController {
private transient ServiceLocator serviceLocator;
private WebApplicationContext context;
private Integer accessLevel; // access level is unmutable
private boolean redirect;
private String urlRedirect;
// this map is used to retrieve a view via a value (see struts "findForwared")
private Map<String, String> conditionalViews;
public AbstractSimpleFormController() {
// by default the user is authorized the view the page
this(0);
}
public AbstractSimpleFormController (Integer accessLevel) {
super();
if (accessLevel == null) {
throw new IllegalArgumentException("access level can not be null");
}
this.accessLevel = accessLevel;
// Spring imposes to the developpers to set the view name
// but in some case the developper won't do it because he/she preffers to use the redirect mechanisme.
// So by setting an empty view name, we make the developer's life more easy.
setSuccessView("");
// the developper must precise He/She would like to use the redirect mechanism.
setRedirect(false);
}
public void setConditionalViews(Map<String, String> conditionalViews) {
this.conditionalViews = conditionalViews;
}
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
if (!redirect) {
return super.onSubmit(request, response, command, errors);
} else{
return new ModelAndView(new RedirectView(urlRedirect));
}
}
protected ModelAndView onSubmit(HttpServletRequest request, String value) throws Exception {
if (!redirect) {
return new ModelAndView(conditionalViews.get(value));
} else{
return new ModelAndView(new RedirectView(conditionalViews.get(value)));
}
}
public boolean isRedirect() {
return redirect;
}
public void setRedirect(boolean redirect) {
this.redirect = redirect;
}
public String getUrlRedirect() {
return urlRedirect;
}
public void setUrlRedirect(String urlRedirect) {
this.urlRedirect = urlRedirect;
}
@Override
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
Map reference = super.referenceData(request, command, errors);
if (reference == null) {
reference = new HashMap();
}
return reference;
}
@Override
protected Map referenceData(HttpServletRequest request) throws Exception {
Map reference = super.referenceData(request);
if (reference == null) {
reference = new HashMap();
}
return reference;
}
public Object getSpringBean(String beanId) {
if (context == null) {
context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
}
return context.getBean(beanId);
}
public ServiceLocator getServiceLocator() {
if (serviceLocator == null) {
serviceLocator = (ServiceLocator) getSpringBean("serviceLocator");
}
return serviceLocator;
}
public Integer getAccessLevel() {
return accessLevel;
}
} |
Merci.