views:

1293

answers:

4

Probably missing something completely obvious here, but here goes. I'm starting out with Spring MVC. I have a form controller to process inbound requests to /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: 

Did you check your log output? Spring MVC is generally pretty verbose in what it outputs.

Also, the URL you've posted (/inbox/share/share/edit) does not seem to match what you are configuring (/share/edit.html).

matt b
I think that's the problem. /inbox/share/edit.html is the URL I'm trying to get the Controller to listen to. Why would the path name repeat?
jordan002
Not sure. Could be issue with mapping from URL to controller of issue with resolving a view. Really, check the logs.
matt b
+1  A: 

You should look at your view resolver. Make sure that it is resolving the logical name in your controller as you think it should. Looks like the name it is resolving it to does not exist currently

Mike Pone
+1  A: 

I think I've resolved this issue. There were two problems:

1) Implementations of SimpleFormController require a form and success view; which I had not configured here. As this is a server method for an AJAX client, I added a Spring-JSON view as follows:

<?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="none">

<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 a 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 got me through the task.

jordan002
A: 

@jordan002 when I see all the hoops you had to jump to accomplish your task, I feel obliged to share a very powerful Java MVC framework that requires much less configuration. The framework is called Induction, check out the article Induction vs. Spring MVC, http://www.inductionframework.org/induction-vs-spring-mvc.html

bluecarbon