Spring MVC - Form Mapping
Probably something completely obvious is missing here, but here. I am starting with Spring MVC. I have a form controller to handle incoming requests in /share/edit.html. When I hit this URL from my browser, I get the following error:
The requested resource (/inbox/share/share/edit) is not available.
Here is my applicationContext-mvc.xml:
<bean id="publicUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="mappings" >
<value>
/share/edit.html=shareFormController
/share/list.html=shareController
/share/view.html=shareController
/folders.json=foldersController
/studies.json=studiesController
</value>
</property>
</bean>
<bean id="internalPathMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver" />
<bean id="shareFormController" class="com.lifeimage.lila.controller.ShareFormController" />
<bean id="shareController" class="com.lifeimage.lila.controller.ShareController" >
<property name="methodNameResolver" ref="internalPathMethodNameResolver" />
</bean>
and my form controller:
public class ShareFormController extends SimpleFormController {
public ShareFormController() {
setCommandClass( Share.class );
}
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
throws Exception {
//controller impl...
}
}
a source to share
I think I solved this problem. There were two problems:
1) SimpleFormController implementations require form submission and success; which I have not configured here. Since this is a server side method for an AJAX client, I added a Spring-JSON view like this:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring - beans -2.5.xsd "default-lazy-init =" false "default-autowire =" no "default-dependency check =" no ">
<bean name="jsonView" class="org.springframework.web.servlet.view.json.JsonView">
<property name="jsonErrors">
<list>
<ref bean="statusError" />
<ref bean="modelflagError" />
</list>
</property>
</bean>
<bean name="statusError"
class="org.springframework.web.servlet.view.json.error.HttpStatusError">
<property name="errorCode"><value>311</value></property>
</bean>
<bean name="modelflagError"
class="org.springframework.web.servlet.view.json.error.ModelFlagError">
<property name="name"><value>failure</value></property>
<property name="value"><value>true</value></property>
</bean>
which can be used for all controllers that return JSON.
2) I switched from SimpleURLHandlerMapping to ControllerClassNameHandlerMapping and relied on Spring naming conventions (controllerClassName / method.html) which fixed the routing issue. Might not be a long term solution, but helped me solve this problem.
a source to share
@ jordan002 when I see all the hoops you needed to complete your task, I believe I should be sharing a very powerful Java MVC framework that requires much less configuration. The structure is called Induction, check out the article Induction vs. Spring MVC, http://www.inductionframework.org/induction-vs-spring-mvc.html
a source to share