Results 1 to 4 of 4

Thread: Question on Multi-Action Controller

  1. #1
    Join Date
    Nov 2004
    Posts
    7

    Default Question on Multi-Action Controller

    Hi everyone,

    Just curious what's the real benefit of a multi-action controller.

    According to the documentation, a multi-action controller is ideally used for mapping multiple entries to the same controller (i.e. grouping of similar functionalities). Borrowing the codes from the Spring documentation (below), we mappy multiple requests into "retrieveIndex" which is defined in the delegate class.

    =======COPY AND PASTE FROM SPRING DOCUMENTATION========
    <bean id="propsResolver" class="org....mvc.multiaction.PropertiesMethodName Resolver">
    <property name="mappings">
    <props>
    <prop key="/index/welcome.html">retrieveIndex</prop>
    <prop key="/**/notwelcome.html">retrieveIndex</prop>
    <prop key="/*/user?.html">retrieveIndex</prop>
    </props>
    </property>
    </bean>

    <bean id="paramMultiController" class="org....mvc.multiaction.MultiActionControlle r">
    <property name="methodNameResolver"><ref bean="propsResolver"/></property>
    <property name="delegate"><ref bean="sampleDelegate"/>
    </bean>

    public class SampleDelegate {

    public ModelAndView retrieveIndex(
    HttpServletRequest req,
    HttpServletResponse resp) {

    rerurn new ModelAndView("index", "date", new Long(System.currentTimeMillis()));
    }
    }
    =====COPY AND PASTE FROM SPRING DOCUMENTATION======

    I just wonder why do we bother using the multi-action controller when we can do something like:

    =========WITHOUT USING MULTI-ACTION CONTROLLER=====
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/index/welcome.html">myController</prop>
    <prop key="/**/notwelcome.html">myController</prop>
    <prop key="/*/user?.html">myController</prop>
    </props>
    </property>
    </bean>
    <bean id="myController" class="com.web.controller.MyController">
    <property name="successView"><value>myView</value></property>
    </bean>
    =========WITHOUT USING MULTI-ACTION CONTROLLER=====

    As you can see in my example, MyController simply extends from "Controller" and multiple requests are mapped into this one controller.

    Maybe I've missed something, but I don't see any value of spending the extra effort to configure the application to use the multi-action controller.

    Thanks for your time.

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    The thing is that with a multi-action controller a single controller can handle multiple types of requests. The example in the docs is very bad since you are still handling only a single type of request ("retreiveIndex"), that's why you can indeed do the same with a normal controller as you show.

    A better example would be a shopping-cart multi-action controller. This would allow you to bundle all shopper-cart functionality together in a single class: listContents, addItem, removeItem, ...

    Ofcourse you would only want to do this if the functions you are bundling together are sufficiently simple, otherwise you would get a very large and complex multi-action controller.

    Erwin

  3. #3
    Join Date
    Aug 2004
    Location
    Auburn, AL, USA.
    Posts
    106

    Default

    Just as a brief addition: with the MultiActionController you are actually mapping to different method calls; so you can put common functionality in a couple of protected methods, and then use those from more than one public method depending on the mapping (for instance CRUD type functionality). Of course there are other ways to accomplish the same thing, which depending on your design may be more appropriate.

  4. #4
    Join Date
    Nov 2009
    Posts
    1

    Default FYI: I found out a good example on below link


Similar Threads

  1. View to forward to another controller?
    By justinp in forum Web
    Replies: 6
    Last Post: Apr 2nd, 2010, 01:53 PM
  2. SWF Basic question 1
    By yfmoan in forum Web Flow
    Replies: 32
    Last Post: May 17th, 2005, 08:52 AM
  3. Newbie Question: General Controller / Manager?
    By pulse1014 in forum Architecture
    Replies: 14
    Last Post: Dec 17th, 2004, 03:17 PM
  4. Replies: 5
    Last Post: Dec 14th, 2004, 04:22 PM
  5. Question about Action
    By snpe in forum Swing
    Replies: 3
    Last Post: Nov 8th, 2004, 08:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •