Ascendant
Ascendant

Reputation: 827

How to set default method for Delegate method of MultiActionController ?

I'm using Spring MVC for a web app project and I'm trying to avoid using annotations.

I came across as far as getting MultiActionController and delegate working.

The question is, how do I set the default method in the delegate of a MultiActionController ?

By MultiActionController, I mean something like this

public class TestController1 extends MultiActionController{

    public TestController1(){
        System.out.println("TestController1 initialising...");
    }
}

My xml settings are...

<bean id="multiactionController1" class="test.TestController1">
    <property name="delegate" ref="testDelegater1"/>    
    <property name="methodNameResolver" ref="paramResolver"/>
</bean>

<!-- Delegaters -->
<bean id="testDelegater1" class="test.TestController1Delegator"/>

<!-- param method name resolver -->
<bean id="paramResolver"  class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
    <property name="paramName" value="action"/>
</bean>
<!-- Simple Url Handler Mapping -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
       <property name="mappings">
          <map>
             <entry key="/multiaction1/**" value-ref="multiactionController1"/>
             <entry key="/item/**" value-ref="itemController"/>
          </map>
       </property>
    </bean>

So when I send a request like '*/item' , notice it doesn't have an action parameter, instead of giving me an error I would like to have a default method.

Upvotes: 2

Views: 1178

Answers (2)

Amit Sargar
Amit Sargar

Reputation: 281

Use following implementation of MethodNameResolver, it has defaultMethodName property.

org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver

Upvotes: 1

Ascendant
Ascendant

Reputation: 827

I was able to solve this by following instructions in this page.
http://www.cwinters.com/blog/2004/02/18/spring_setting_a_default_action_for_multiactioncontroller.html
As far as I've figured, you need to implement your own MethodNameResolver that returns default method name if no method name has been specified.
I Hope this helps : )

Upvotes: 0

Related Questions