Hi,
I m trying to create my own web application using Spring MVC. All goes well until i use <spring:bind> to validate a form. I have followed a tutorial, and i think i did the equivalent of the content of the tutorial, but...
I have an error:This is a part of createApplication-servlet.xml:javax.servlet.ServletException: tried to access method org.springframework.validation.AbstractPropertyBin dingResult.getActualFieldValue
A part of my Controller:Code:<beans> <!-- les mappings de l'application--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/createApplication.html">CreateApplicationController</prop> </props> </property> </bean> <!-- les contrôleurs de l'application--> <bean id="CreateApplicationController" class="controller.CreateApplicationController" autowire="byName"> <property name="sessionForm"> <value>true</value> </property> <property name="commandName"> <value>createApplicationForm</value> </property> <property name="formView"> <value>createApplication</value> </property> <property name="successView"> <value>confirmCreateApplication</value> </property> <property name="validator"> <ref bean="createApplicationFormValidator"/> </property> </bean> <!-- le validateur de formulaire --> <bean id="createApplicationFormValidator" class="controller.validator.ValidateCreateApplicationForm"/>
My form object:Code:public class CreateApplicationController extends SimpleFormController { private ApplicationManager applicationManager; public ApplicationManager getApplicationManager() { return applicationManager; } public void setApplicationManager(ApplicationManager applicationManager) { this.applicationManager = applicationManager; } private ModelAndView create(HttpServletRequest request, HttpServletResponse response) { CreateApplicationForm createApplicationForm = (CreateApplicationForm) request.getSession().getAttribute( "createApplicationForm"); Application app = new Application(); app.setComment(createApplicationForm.getComment()); app.setName(createApplicationForm.getName()); app.setTrigram(createApplicationForm.getTrigram()); applicationManager.add(app); // on rend un [ModelAndView] return new ModelAndView("confirmCreateApplication", null); } protected Object formBackingObject(HttpServletRequest request) { // on récupère le formulaire dans la session s'il existe CreateApplicationForm createApplicationForm = (CreateApplicationForm) request.getSession().getAttribute( "createApplicationForm"); if (createApplicationForm == null) { createApplicationForm = new CreateApplicationForm(); } // on rend le formulaire return createApplicationForm; } // traitement du POST protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object createApplicationForm, BindException errors) { // on met le formulaire dans la session request.getSession().setAttribute("createApplicationForm", createApplicationForm); // on rend un [ModelAndView] return create(request, response); } }
and hte jsp i cannot display:Code:public class CreateApplicationForm { /** * Le nom de l'application */ private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }
It looks that the bolded part is a problem: when i try to display my form, instead of display the empty input field, i have:Code:<body> createApplication <form method="post"> <table> <tr> <spring:bind path="createApplicationForm.name"> <td><input type="text" name="${status.expression}" value="${status.value}" /></td> <td>${status.errorMessage}</td> </spring:bind> </tr> </table> </form> </body>
The only difference with the tuto i followed is that an instance of the form object is created in its business interface (= applicationManager for me) to init the attributes. I tried it too but it didnt change anything. So i desperatly ask for your helpCode:org.apache.jasper.JasperException: Exception in JSP: /views/createApplication.jsp:17 14: <form method="post"> 15: <table> 16: <tr> 17: <spring:bind path="createApplicationForm.name"> 18: 19: <td><input type="text" name="${status.expression}" value="${status.value}" /></td> 20: <td>${status.errorMessage}</td> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause javax.servlet.ServletException: tried to access method org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(Ljava/lang/String;)Ljava/lang/Object; from class org.springframework.web.servlet.support.BindStatus org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774) org.apache.jsp.views.createApplication_jsp._jspService(createApplication_jsp.java:135) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Thanks in advance



Reply With Quote
