Bonjour,
J'ai une erreur au retour d'un formulaire d'une page JSP et je ne comprends pas ce qui cloche...
Au départ, j'ai un model User qui possède une référence vers une classe Authorities.
Dans mon controller, je décide d'afficher l'état d'un user :
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 @Entity @Table(name = "USER") public class Users extends AbstractGenericEntity { private static final long serialVersionUID = -8865263456343696037L; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="supp_seq_users") @SequenceGenerator(name="supp_seq_users", sequenceName="SEQUENCEUSERS") @Basic(optional = false) @Column(name = "IDUSERS", nullable = false, precision = 22, scale = 0) private Long idusers; @Basic(optional = false) @Column(name = "USERNAME", nullable = false, length = 64) private String userName; @Basic(optional = false) @Column(name = "PASSWORD", nullable = false, length = 64) private String password; @Basic(optional = true) @Column(name = "EMAIL", nullable = true, length = 64) private String email; @Basic(optional = false) @Column(name = "ENABLED", nullable = false, length = 38) private Boolean enabled; @ForeignKey(name = "IDAUTHORITIESFK") @JoinColumn(name = "IDAUTHORITIESFK", referencedColumnName = "IDAUTHORITIES", insertable=true, updatable=true) @ManyToOne(fetch = FetchType.EAGER) private Authorities authorities; etc... }
La page JSP qui s'occupe de l'affichage, la voilà :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 @RequestMapping(value="/user/addEdit.do") public String addEdit(@RequestParam(value="id", required=false) Long id, ModelMap model) { logger.info("UserController, edit for update a user"); Users user = null; if (id != null) { user = this.userService.findByIduser(id); model.addAttribute("user", user); return "editUser"; } return "toto"; }
Donc dans cette page, il y a deux radios boutons qui permettent de choisir entre "l'authorities" ROLE_ADMIN ou ROLE_USER.
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 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib uri='http://java.sun.com/jsp/jstl/functions' prefix='fn'%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <c:url var="url" value="/user/edit.do" /> <CENTER> <div id="part" class="indexlayout"> <form:form action="${url}" commandName="user"> <form:hidden path="authorities" /> <form:hidden path="password" /> <form:hidden path="idusers" /> <p class="mandatory"><spring:message code="mandatory.field" /></p> <h2><spring:message code="user.addedit.title" /></h2> <tr> <span class="form-error-message"> <form:errors path="userName" /><br /> <form:errors path="email" /><br /> <form:errors path="authorities" /><br /> </span> </tr> <fieldset> <table> <tr> <td> <label for="username"><b><spring:message code="user.addedit.username" /></b></label> <form:input path="userName" cssErrorClass="form-error-field" id="userNameField" /> <span class="mandatory">*</span></td> </tr> <tr> <td> <label for="email"><b><spring:message code="user.addedit.email" /></b></label> <form:input path="email" cssErrorClass="form-error-field" id="emailField" /> <span class="mandatory">*</span></td> </tr> <tr> <td> <label for="enabled"><b><spring:message code="user.addedit.enabled" /></b></label> <form:checkbox path="enabled" cssErrorClass="form-error-field" id="enabledField" value="<spring:message code='user.addedit.enabled'/>" /> </td> </tr> <tr> <td> <label for="user_role"><b><spring:message code="user.addedit.role" /></b></label> <form:radiobutton path="authorities.role" value="ROLE_ADMIN" /> <label for="role_admin" class="nofloat"><b><spring:message code="user.authorities.administrator" /></b></label> <form:radiobutton path="authorities.role" value="ROLE_USER" /> <label for="role_user" class="nofloat"><b><spring:message code="user.authorities.user" /></b></label> </td> </tr> <tr> <td> <hr /> </td> </tr> <tr> <td> <button type="submit"><spring:message code="button.label.save"/></button> <button type="button" onClick="location.href='<c:url value="/user/list.do"/>'"><spring:message code="operation.cancelAction" /></button> </td> </tr> </table> </fieldset> </form:form> </div> </CENTER>
A l'affichage, pas de problème, pour un user donné, le bon radio bouton est sélectionné.
Puis, si je décide de modifier quoi que ce soit dans cette page pour retourner vers le contrôleur, j'ai de suite une erreur qui apparaît dès que j'ai appuyé
sur le bouton "submit", je ne retourne d'ailleurs jamais dans le contrôleur.
L'erreur est la suivante :
Il me dit que l'attribut "authorities" est null... Pourquoi ??
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 org.springframework.beans.NullValueInNestedPathException: Invalid property 'authorities' of bean class [com.jva.disc.beans.Users]: Value of nested property 'authorities' is null at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:449) at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:424) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:641) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78) at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:587) at org.springframework.validation.DataBinder.doBind(DataBinder.java:489) at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:149) at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:110) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:566) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:213) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:132) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511) at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378) at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.concurrent.ConcurrentSessionFilter.doFilterHttp(ConcurrentSessionFilter.java:99) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
Une connaissance m'a dit que le protocole HTTP est stateless (chose que je savais) et qu'il fallait ajouter dans le form, cette instruction :
<form:hidden path="authorities" />
Chose que j'ai faite, mais j'ai tjs cette erreur...
Si quelqu'un a une idée, je suis preneur...
Partager