Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController not do onSubmit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController not do onSubmit

    Hi,

    I am doing an application with SimpleFormController, but the method onSubmit not is called.
    The Success View is show, bud i still can't make it work, doing my bussiness action in onSubmit .

    Anyone can help ?

    Here is my code:

    1) measurementplanning-servlet.xml
    Code:
    <beans>
    
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
                <property name="basename" value="views"/>
    	</bean>
    
    	<!--
    	 - This bean is an explicit URL mapper that is used by the "petclinic" DispatcherServlet
    	 - It is used instead of the default BeanNameUrlHandlerMapping.
    	 -->
    	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                <property name="mappings">
                    <props>
                        <prop key="/bemvindo.htm">mpController</prop>
                        <prop key="/uc1_BuscarProjeto.htm">buscarProjetoForm</prop>				
                        <prop key="/uc1_EditarProjeto.htm">editarProjetoForm</prop>
                        <prop key="/uc1_DeletarProjeto.htm">deletarProjetoForm</prop>                    
                    </props>
                </property>
    	</bean>
    
    	<!-- ========================= CONTROLLER DEFINITIONS ========================= -->
    
    	<!--
    	  - This bean is a MultiActionController that manages general View rendering.
    	  - It uses the "mpControllerResolver" bean below for method name resolution.
    	  -->
    	<bean id="mpController" class="org.heleno.mp.spring.MeasurementPlanningController">
    		<property name="methodNameResolver" ref="mpControllerResolver"/>
    	</bean>
    
    	<!--
    	  - This bean is a MethodNameResolver definition for a MultiActionController.
    	  - It maps URLs to methods for the "mpController" bean.
    	  -->
    	<bean id="mpControllerResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
    		<property name="mappings">
    		<props>
    			<prop key="/bemvindo.htm">bemvindoHandler</prop>
    		</props>
    		</property>
    	</bean>
    
    	<!--
    	  - This bean is a SimpleFormController that manages the CRUDProjeto / Retrieve use case.
    	  -->
    	<bean id="buscarProjetoForm" class="org.heleno.mp.spring.BuscarProjetoForm">
                <property name="formView" value="buscarProjetoForm"/>
                <property name="successView" value="buscarProjetoForm"/>
                <property name="commandName" value="projeto"/>
                <property name="commandClass" value="org.heleno.mp.beans.Projeto"/>  			        		
    			<property name="bindOnNewForm" value="true"/>            
    			<property name="sessionForm" value="false"/>			
                <property name="projetoBussiness" ref="projetoBussinessTarget"/>
    	</bean>
    
    	<!--
    	  - This bean is a SimpleFormController that manages the CRUDProjeto / Create and Update use case.
    	  -->
    	<bean id="editarProjetoForm" class="org.heleno.mp.spring.EditarProjetoForm">
                <property name="formView" value="editarProjetoForm"/>
                <property name="successView" value="projetoRedirect"/>
                <property name="commandName" value="projeto"/>
                <property name="commandClass" value="org.heleno.mp.beans.Projeto"/>
    			<property name="bindOnNewForm" value="true"/>
    			<property name="sessionForm" value="false"/>						
                <property name="projetoBussiness" ref="projetoBussinessTarget"/>            
    	</bean>
    2) views.properties

    Code:
    buscarProjetoForm.class=org.springframework.web.servlet.view.JstlView
    buscarProjetoForm.url=WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp
    
    editarProjetoForm.class=org.springframework.web.servlet.view.JstlView
    editarProjetoForm.url=WEB-INF/jsp/uc1_CRUDProjetoViewB.jsp
    
    projetoRedirect.class=org.springframework.web.servlet.view.RedirectView
    projetoRedirect.url=uc1_BuscarProjeto.htm
    
    bemvindo.class=org.springframework.web.servlet.view.JstlView
    bemvindo.url=WEB-INF/jsp/bemvindo.jsp
    3) EditarProjetoForm.java

    Code:
    public class EditarProjetoForm extends ProjetoForm &#123;
    	protected final Log logger = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
    
        protected Object formBackingObject&#40;HttpServletRequest request&#41; throws ServletException &#123;
        		Projeto projeto = new Projeto&#40;&#41;;
        		Long projetoId = Long.getLong&#40;RequestUtils.getStringParameter&#40;request, "projetoId"&#41;&#41;;
        		if&#40;projetoId != null&#41;&#123;
        			projeto.setId&#40;projetoId&#41;;
                    getProjetoBussiness&#40;&#41;.carregarProjeto&#40;projeto&#41;;
        		&#125;
                
        		logger.info&#40;"Abrindo Form para Editar/Criar Projeto &#123;" +projetoId+ "&#125;"&#41;;
                logger.info&#40;"View Sucesso &#58; " + getSuccessView&#40;&#41;&#41;;
                
                return projeto;
        &#125;
        
        protected void initBinder&#40;HttpServletRequest request, ServletRequestDataBinder binder&#41;&#123;
            SimpleDateFormat dateFormat = new SimpleDateFormat&#40;"dd/MM/yyyy"&#41;;
            dateFormat.setLenient&#40;false&#41;;
            binder.registerCustomEditor&#40;Date.class, null, new CustomDateEditor&#40;dateFormat, true&#41;&#41;;
            binder.registerCustomEditor&#40;Long.class, null, new CustomNumberEditor&#40;Long.class, true&#41;&#41;;
        &#125;
    
    	protected ModelAndView onSubmit&#40;
    			HttpServletRequest request, HttpServletResponse response, Object command, BindException errors&#41; throws ServletException &#123;
        		logger.info&#40;"Submetendo Form de Projeto"&#41;;
                setProjeto&#40;&#40;Projeto&#41; command&#41;;
                // delegate the update to the business layer
                getProjetoBussiness&#40;&#41;.salvarOuAtualizarProjeto&#40;projeto&#41;;
                logger.info&#40;"Salvo ... Retornando para " + getSuccessView&#40;&#41;&#41;;
                ModelAndView retorno = new ModelAndView&#40;new RedirectView&#40;getSuccessView&#40;&#41;&#41;&#41;;            
                return retorno;
        &#125;
    &#125;
    4) ProjetoForm.java

    Code:
    public class ProjetoForm extends SimpleFormController &#123;
        protected Projeto projeto;
        protected ProjetoBussiness projetoBussiness;
                    
        public Projeto getProjeto&#40;&#41;&#123;
            return this.projeto;
        &#125;
            
        public void setProjeto&#40;Projeto projeto&#41;&#123;
            this.projeto = projeto;
        &#125;
        
        public ProjetoBussiness getProjetoBussiness&#40;&#41;&#123;
            return this.projetoBussiness;
        &#125;
        
        public void setProjetoBussiness&#40;ProjetoBussiness projetoBussiness&#41;&#123;
            this.projetoBussiness = projetoBussiness;
        &#125;
        
    &#125;


    The log after i click a button for submit is

    Code:
    2005-10-18 00&#58;17&#58;14,968 DEBUG &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <DispatcherServlet with name 'measurementplanning' received request for &#91;/measurementplanning/uc1_EditarProjeto.htm&#93;>
    2005-10-18 00&#58;17&#58;14,984 DEBUG &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Testing handler map &#91;[email protected]c86961&#93; in DispatcherServlet with name 'measurementplanning'>
    2005-10-18 00&#58;17&#58;14,984 DEBUG &#91;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&#93; - <Looking up handler for &#91;/uc1_EditarProjeto.htm&#93;>
    2005-10-18 00&#58;17&#58;14,984 DEBUG &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Testing handler adapter &#91;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@1395158&#93;>
    2005-10-18 00&#58;17&#58;14,984 INFO &#91;org.heleno.mp.spring.EditarProjetoForm&#93; - <Abrindo Form para Editar/Criar Projeto &#123;null&#125;>
    2005-10-18 00&#58;17&#58;14,984 INFO &#91;org.heleno.mp.spring.EditarProjetoForm&#93; - <View Sucesso &#58; projetoRedirect>
    2005-10-18 00&#58;17&#58;14,984 DEBUG &#91;org.springframework.beans.CachedIntrospectionResults&#93; - <Using cached introspection results for class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,000 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setDescricao&#40;java.lang.String&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setDescricao&#40;java.lang.String&#41;&#93; with value of type &#91;java.lang.String&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setEstado&#40;java.lang.String&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setEstado&#40;java.lang.String&#41;&#93; with value of type &#91;java.lang.String&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Converting String to &#91;class java.util.Date&#93; using property editor &#91;[email protected]3&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setFim&#40;java.util.Date&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,031 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setFim&#40;java.util.Date&#41;&#93; with value of type &#91;java.util.Date&#93;>
    2005-10-18 00&#58;17&#58;15,046 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setGerente&#40;java.lang.String&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,062 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setGerente&#40;java.lang.String&#41;&#93; with value of type &#91;java.lang.String&#93;>
    2005-10-18 00&#58;17&#58;15,062 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Converting String to &#91;class java.lang.Long&#93; using property editor &#91;[email protected]c1a&#93;>
    2005-10-18 00&#58;17&#58;15,062 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Entity.setId&#40;java.lang.Long&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Entity.setId&#40;java.lang.Long&#41;&#93; with value of type &#91;java.lang.Long&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Converting String to &#91;class java.util.Date&#93; using property editor &#91;[email protected]3&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setInicio&#40;java.util.Date&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setInicio&#40;java.util.Date&#41;&#93; with value of type &#91;java.util.Date&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Converting String array to comma-delimited String &#91;&#91;Ljava.lang.String;@3abdd5&#93;>
    2005-10-18 00&#58;17&#58;15,078 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Converting String to &#91;class java.lang.String&#93; using property editor &#91;sun.beans.editors.StringEditor@ca838f&#93;>
    2005-10-18 00&#58;17&#58;15,093 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke write method &#91;public void org.heleno.mp.beans.Projeto.setNome&#40;java.lang.String&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,093 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <Invoked write method &#91;public void org.heleno.mp.beans.Projeto.setNome&#40;java.lang.String&#41;&#93; with value of type &#91;java.lang.String&#93;>
    2005-10-18 00&#58;17&#58;15,093 DEBUG &#91;org.heleno.mp.spring.EditarProjetoForm&#93; - <No errors -> processing submit>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Rendering view &#91;org.springframework.web.servlet.view.JstlView&#58; name 'projetoRedirect'; URL &#91;WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp&#93;&#93; in DispatcherServlet with name 'measurementplanning'>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.springframework.web.servlet.view.JstlView&#93; - <Rendering view with name 'projetoRedirect' with model &#123;projeto=org.heleno.mp.beans.Projeto@7e3fb6, org.springframework.validation.BindException.projeto=org.springframework.validation.BindException&#58; BindException&#58; 0 errors&#125; and static attributes &#123;&#125;>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.springframework.web.servlet.view.JstlView&#93; - <Added model object 'projeto' of type &#91;org.heleno.mp.beans.Projeto&#93; to request in InternalResourceView 'projetoRedirect'>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.springframework.web.servlet.view.JstlView&#93; - <Added model object 'org.springframework.validation.BindException.projeto' of type &#91;org.springframework.validation.BindException&#93; to request in InternalResourceView 'projetoRedirect'>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.apache.catalina.core.ApplicationDispatcher&#93; - <servletPath=/WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp, pathInfo=null, queryString=null, name=null>
    2005-10-18 00&#58;17&#58;15,109 DEBUG &#91;org.apache.catalina.core.ApplicationDispatcher&#93; - < Path Based Forward>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <JspEngine --> /WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	     ServletPath&#58; /WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	        PathInfo&#58; null>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	        RealPath&#58; C&#58;\Projeto TCC\measurementplanning\.deployables\measurementplanning\WEB-INF\jsp\uc1_CRUDProjetoViewA.jsp>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	      RequestURI&#58; /measurementplanning/WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	     QueryString&#58; criar=Criar+Projeto>
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <	  Request Params&#58; >
    2005-10-18 00&#58;17&#58;15,125 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 nome = Heleno2>
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 fim = 25/10/2005>
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 descricao = Uma Descricao
                                            >
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 salvar = Salvar>
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 gerente = Nino2>
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 criar = Criar Projeto>
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 estado = >
    2005-10-18 00&#58;17&#58;15,140 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 id = >
    2005-10-18 00&#58;17&#58;15,156 DEBUG &#91;org.apache.jasper.servlet.JspServlet&#93; - <		 inicio = 12/10/2005>
    2005-10-18 00&#58;17&#58;15,156 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke read method &#91;public java.lang.String org.heleno.mp.beans.Projeto.getNome&#40;&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,156 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke read method &#91;public java.lang.String org.heleno.mp.beans.Projeto.getGerente&#40;&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,156 DEBUG &#91;org.springframework.beans.BeanWrapperImpl&#93; - <About to invoke read method &#91;public java.lang.String org.heleno.mp.beans.Projeto.getEstado&#40;&#41;&#93; on object of class &#91;org.heleno.mp.beans.Projeto&#93;>
    2005-10-18 00&#58;17&#58;15,156 DEBUG &#91;org.apache.catalina.core.ApplicationDispatcher&#93; - < Disabling the response for futher output>
    2005-10-18 00&#58;17&#58;15,171 DEBUG &#91;org.springframework.web.servlet.view.JstlView&#93; - <Forwarded to resource &#91;WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp&#93; in InternalResourceView 'projetoRedirect'>
    2005-10-18 00&#58;17&#58;15,171 DEBUG &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Successfully completed request>
    2005-10-18 00&#58;17&#58;15,171 DEBUG &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; - <Publishing event in context &#91;WebApplicationContext for namespace 'measurementplanning-servlet'&#93;&#58; RequestHandledEvent&#58; url=&#91;/measurementplanning/uc1_EditarProjeto.htm&#93;; time=&#91;203ms&#93;; client=&#91;127.0.0.1&#93;; method=&#91;POST&#93;; servlet=&#91;measurementplanning&#93;; session=&#91;null&#93;; user=&#91;null&#93;; status=&#91;OK&#93;>
    2005-10-18 00&#58;17&#58;15,171 DEBUG &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; - <Publishing event in context &#91;Root WebApplicationContext&#93;&#58; RequestHandledEvent&#58; url=&#91;/measurementplanning/uc1_EditarProjeto.htm&#93;; time=&#91;203ms&#93;; client=&#91;127.0.0.1&#93;; method=&#91;POST&#93;; servlet=&#91;measurementplanning&#93;; session=&#91;null&#93;; user=&#91;null&#93;; status=&#91;OK&#93;>
    What i doing wrong ... ?
    Anyone can help ? :?

    Thanks ...

  • #2
    Are you doing a POST?

    If not you need to override isFormSubmission

    Comment


    • #3
      katentin;

      My classs EditarProjeto.java Is the same that i show before, but the onSubmit method is not working.

      So, on eclipse, I override all super class method and my class EditarProjetoForm.java compile with two equal methods, it's exactly the same method (same args, return and name), :shock: one chain after submit other not. So i change the bussiness role place !!!

      Now it's working .... :lol:

      Thanks for help.

      Comment

      Working...
      X