Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Behaviour of handleRequest() in MultiActionController

  1. #11
    Join Date
    Aug 2008
    Location
    St Louis, MO
    Posts
    51

    Default

    Quote Originally Posted by va1224 View Post
    This is what i see in the log file:

    INFO: Inside handleRequestInternal
    Aug 20, 2008 10:40:04 AM org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController handleNoSuchRequestHandlingMethod
    WARNING: No matching handler method found for servlet request: path '/eirapp/actadmin.htm', method 'GET', parameters map[[empty]]
    I think this is where the problem is. The controller is getting a "GET" request without any parameters & is unable to resolve a method from the method resolver to execute the action. What you could do is in your bean definition add a default method as below & let it handle all the "GET" requests similar to the showForm in SimpleFormController.

    Code:
    <bean id="paramResolver"
    		class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
                    <property name="defaultMethodName" value="showForm"/>
    		<property name="methodParamNames">
    		<list>
    			<value>addAccount</value>
    			<value>updateAccount</value>
    			<value>disableAccount</value>
    		</list>
    		</property>
    	</bean>
    and in your controller

    Code:
    public ModelAndView showForm(HttpServletRequest httpServletRequest,
    			HttpServletResponse httpServletResponse) {
    		return new ModelAndView("pageYouWantToShowOnInitialPageDisplay");
    	}

  2. #12
    Join Date
    Jul 2008
    Posts
    15

    Thumbs up

    Thank you very much. That worked for me. One last question do i have to always have this default method to handle GETS in my controller?

    For everyone, in case you have struggled like me to make this controller work.

    Case

    How do we go about using a MultiActionController to provide a simple CRUD JSP.

    JSP PAGE
    Code:
    <!-- Form & Javascript -->
    <script type="text/javascript">
    function dispatch(_param) {
    document.eirform.param.value = _param;
    }			
    </script>
    <form:form name="eirform" method="POST">
    <input type="hidden" name="param" />
    
    <!-- HTML Snippet -->
    <TABLE border=0 cellpadding=2 cellspacing=1 align="center">
    		<TR>
    			<TD align="center" noWrap>
    				<input class=button type="submit" name="addAccount" value="Add New Account" onclick="dispatch('addAccount')"/>		
    			</TD>
    			<TD align="center" noWrap>
    				<input class=button type="submit" name="updateAccount" value="Update Existing Account" onclick="dispatch('updateAccount')"/>		
    			</TD>
    			<TD align="center" noWrap>
    				<input class=button type="submit" name="disableAccount" value="Disable Account" onclick="dispatch('disableAccount')"/>	
    			</TD>
    			<TD align="center" noWrap>
    				<input class=button type="submit" name="clear" value="Clear">
    			</TD>
    			<TD align="center" noWrap>
    				<input class=button type="submit" value="Exit">				
    			</TD>
    		</TR>
    	</TABLE>
    Spring Controller Config File

    <bean name="/actadmin.htm" class="eirapp.controller.AccountController">
    <property name="accountManager" ref="accountManager" />
    <property name="methodNameResolver">
    <ref bean="paramResolver" />
    </property>
    </bean>
    <bean id="paramResolver" class="org.springframework.web.servlet.mvc.multiac tion.ParameterMethodNameResolver">
    <property name="defaultMethodName" value="showForm" />
    <property name="methodParamNames">
    <list>
    <value>addAccount</value>
    <value>updateAccount</value>
    <value>disableAccount</value>
    </list>
    </property>
    </bean>

    Note: The line in RED was required to make this work.
    I think this is where the problem is. The controller is getting a "GET" request without any parameters & is unable to resolve a method from the method resolver to execute the action. What you could do is in your bean definition add a default method as below & let it handle all the "GET" requests similar to the showForm in SimpleFormController.

    Controller Code

    Code:
    package eirapp.controller;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
    
    import eirapp.service.AccountManager;
    
    public class AccountController extends MultiActionController {
    
    	protected final Log logger = LogFactory.getLog(getClass());
    	private AccountManager accountManager;
    
    	public ModelAndView showForm(HttpServletRequest httpServletRequest,
                HttpServletResponse httpServletResponse) {
    		String now = (new java.util.Date()).toString();
    		Map<String, Object> myModel = new HashMap<String, Object>();
    		myModel.put("now", now);
    		myModel.put("accounts", this.accountManager.getAccounts());
    		return new ModelAndView("actadmin", "model", myModel);
        }
    	
    	public ModelAndView handleRequestInternal(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		logger.info("Inside handleRequestInternal");
    		ModelAndView modelAndView = super.handleRequestInternal(request,
    				response);
    		String now = (new java.util.Date()).toString();
    
    		modelAndView.getModel().put("now", now);
    		modelAndView.getModel().put("accounts", accountManager.getAccounts());
    		return modelAndView;
    	}
    
    	public ModelAndView addAccount(HttpServletRequest httpServletRequest,
    			HttpServletResponse httpServletResponse) {
    		logger.info("******Inside AccountController addAccount Method *******");
    		return new ModelAndView("actadmin");
    	}
    
    	public ModelAndView updateAccount(HttpServletRequest httpServletRequest,
    			HttpServletResponse httpServletResponse) {
    		logger
    				.info("******Inside AccountController updateAccount Method *******");
    		return new ModelAndView("actadmin");
    	}
    
    	public ModelAndView disableAccount(HttpServletRequest httpServletRequest,
    			HttpServletResponse httpServletResponse) {
    		logger
    				.info("******Inside AccountController disableAccount Method *******");
    		return new ModelAndView("actadmin");
    	}
    
    	public void setAccountManager(AccountManager _accountManager) {
    		this.accountManager = _accountManager;
    	}
    
    	public AccountManager getAccountManager() {
    		return accountManager;
    	}
    }
    Many thanks again.

  3. #13
    Join Date
    Aug 2008
    Location
    St Louis, MO
    Posts
    51

    Default

    Yes if you want to use the MultiActionController to display the initial form, then there should be some way for the controller to know what to do on a GET. And I think default method is the best way unless you want to pass in a parameter in the GET which maps to a method, in this case the "showForm".

Posting Permissions

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