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 {
protected final Log logger = LogFactory.getLog(getClass());
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
Projeto projeto = new Projeto();
Long projetoId = Long.getLong(RequestUtils.getStringParameter(request, "projetoId"));
if(projetoId != null){
projeto.setId(projetoId);
getProjetoBussiness().carregarProjeto(projeto);
}
logger.info("Abrindo Form para Editar/Criar Projeto {" +projetoId+ "}");
logger.info("View Sucesso : " + getSuccessView());
return projeto;
}
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder){
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));
binder.registerCustomEditor(Long.class, null, new CustomNumberEditor(Long.class, true));
}
protected ModelAndView onSubmit(
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException {
logger.info("Submetendo Form de Projeto");
setProjeto((Projeto) command);
// delegate the update to the business layer
getProjetoBussiness().salvarOuAtualizarProjeto(projeto);
logger.info("Salvo ... Retornando para " + getSuccessView());
ModelAndView retorno = new ModelAndView(new RedirectView(getSuccessView()));
return retorno;
}
}
4) ProjetoForm.java
Code:
public class ProjetoForm extends SimpleFormController {
protected Projeto projeto;
protected ProjetoBussiness projetoBussiness;
public Projeto getProjeto(){
return this.projeto;
}
public void setProjeto(Projeto projeto){
this.projeto = projeto;
}
public ProjetoBussiness getProjetoBussiness(){
return this.projetoBussiness;
}
public void setProjetoBussiness(ProjetoBussiness projetoBussiness){
this.projetoBussiness = projetoBussiness;
}
}
The log after i click a button for submit is
Code:
2005-10-18 00:17:14,968 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <DispatcherServlet with name 'measurementplanning' received request for [/measurementplanning/uc1_EditarProjeto.htm]>
2005-10-18 00:17:14,984 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@1c86961] in DispatcherServlet with name 'measurementplanning'>
2005-10-18 00:17:14,984 DEBUG [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] - <Looking up handler for [/uc1_EditarProjeto.htm]>
2005-10-18 00:17:14,984 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Testing handler adapter [org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@1395158]>
2005-10-18 00:17:14,984 INFO [org.heleno.mp.spring.EditarProjetoForm] - <Abrindo Form para Editar/Criar Projeto {null}>
2005-10-18 00:17:14,984 INFO [org.heleno.mp.spring.EditarProjetoForm] - <View Sucesso : projetoRedirect>
2005-10-18 00:17:14,984 DEBUG [org.springframework.beans.CachedIntrospectionResults] - <Using cached introspection results for class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,000 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setDescricao(java.lang.String)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setDescricao(java.lang.String)] with value of type [java.lang.String]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setEstado(java.lang.String)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setEstado(java.lang.String)] with value of type [java.lang.String]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Converting String to [class java.util.Date] using property editor [org.springframework.beans.propertyeditors.CustomDateEditor@14052e3]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setFim(java.util.Date)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,031 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setFim(java.util.Date)] with value of type [java.util.Date]>
2005-10-18 00:17:15,046 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setGerente(java.lang.String)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,062 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setGerente(java.lang.String)] with value of type [java.lang.String]>
2005-10-18 00:17:15,062 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Converting String to [class java.lang.Long] using property editor [org.springframework.beans.propertyeditors.CustomNumberEditor@1a56c1a]>
2005-10-18 00:17:15,062 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Entity.setId(java.lang.Long)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Entity.setId(java.lang.Long)] with value of type [java.lang.Long]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Converting String to [class java.util.Date] using property editor [org.springframework.beans.propertyeditors.CustomDateEditor@14052e3]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setInicio(java.util.Date)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setInicio(java.util.Date)] with value of type [java.util.Date]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Converting String array to comma-delimited String [[Ljava.lang.String;@3abdd5]>
2005-10-18 00:17:15,078 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Converting String to [class java.lang.String] using property editor [sun.beans.editors.StringEditor@ca838f]>
2005-10-18 00:17:15,093 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke write method [public void org.heleno.mp.beans.Projeto.setNome(java.lang.String)] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,093 DEBUG [org.springframework.beans.BeanWrapperImpl] - <Invoked write method [public void org.heleno.mp.beans.Projeto.setNome(java.lang.String)] with value of type [java.lang.String]>
2005-10-18 00:17:15,093 DEBUG [org.heleno.mp.spring.EditarProjetoForm] - <No errors -> processing submit>
2005-10-18 00:17:15,109 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Rendering view [org.springframework.web.servlet.view.JstlView: name 'projetoRedirect'; URL [WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp]] in DispatcherServlet with name 'measurementplanning'>
2005-10-18 00:17:15,109 DEBUG [org.springframework.web.servlet.view.JstlView] - <Rendering view with name 'projetoRedirect' with model {projeto=org.heleno.mp.beans.Projeto@7e3fb6, org.springframework.validation.BindException.projeto=org.springframework.validation.BindException: BindException: 0 errors} and static attributes {}>
2005-10-18 00:17:15,109 DEBUG [org.springframework.web.servlet.view.JstlView] - <Added model object 'projeto' of type [org.heleno.mp.beans.Projeto] to request in InternalResourceView 'projetoRedirect'>
2005-10-18 00:17:15,109 DEBUG [org.springframework.web.servlet.view.JstlView] - <Added model object 'org.springframework.validation.BindException.projeto' of type [org.springframework.validation.BindException] to request in InternalResourceView 'projetoRedirect'>
2005-10-18 00:17:15,109 DEBUG [org.apache.catalina.core.ApplicationDispatcher] - <servletPath=/WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp, pathInfo=null, queryString=null, name=null>
2005-10-18 00:17:15,109 DEBUG [org.apache.catalina.core.ApplicationDispatcher] - < Path Based Forward>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - <JspEngine --> /WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < ServletPath: /WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < PathInfo: null>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < RealPath: C:\Projeto TCC\measurementplanning\.deployables\measurementplanning\WEB-INF\jsp\uc1_CRUDProjetoViewA.jsp>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < RequestURI: /measurementplanning/WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < QueryString: criar=Criar+Projeto>
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < Request Params: >
2005-10-18 00:17:15,125 DEBUG [org.apache.jasper.servlet.JspServlet] - < nome = Heleno2>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < fim = 25/10/2005>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < descricao = Uma Descricao
>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < salvar = Salvar>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < gerente = Nino2>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < criar = Criar Projeto>
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < estado = >
2005-10-18 00:17:15,140 DEBUG [org.apache.jasper.servlet.JspServlet] - < id = >
2005-10-18 00:17:15,156 DEBUG [org.apache.jasper.servlet.JspServlet] - < inicio = 12/10/2005>
2005-10-18 00:17:15,156 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke read method [public java.lang.String org.heleno.mp.beans.Projeto.getNome()] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,156 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke read method [public java.lang.String org.heleno.mp.beans.Projeto.getGerente()] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,156 DEBUG [org.springframework.beans.BeanWrapperImpl] - <About to invoke read method [public java.lang.String org.heleno.mp.beans.Projeto.getEstado()] on object of class [org.heleno.mp.beans.Projeto]>
2005-10-18 00:17:15,156 DEBUG [org.apache.catalina.core.ApplicationDispatcher] - < Disabling the response for futher output>
2005-10-18 00:17:15,171 DEBUG [org.springframework.web.servlet.view.JstlView] - <Forwarded to resource [WEB-INF/jsp/uc1_CRUDProjetoViewA.jsp] in InternalResourceView 'projetoRedirect'>
2005-10-18 00:17:15,171 DEBUG [org.springframework.web.servlet.DispatcherServlet] - <Successfully completed request>
2005-10-18 00:17:15,171 DEBUG [org.springframework.web.context.support.XmlWebApplicationContext] - <Publishing event in context [WebApplicationContext for namespace 'measurementplanning-servlet']: RequestHandledEvent: url=[/measurementplanning/uc1_EditarProjeto.htm]; time=[203ms]; client=[127.0.0.1]; method=[POST]; servlet=[measurementplanning]; session=[null]; user=[null]; status=[OK]>
2005-10-18 00:17:15,171 DEBUG [org.springframework.web.context.support.XmlWebApplicationContext] - <Publishing event in context [Root WebApplicationContext]: RequestHandledEvent: url=[/measurementplanning/uc1_EditarProjeto.htm]; time=[203ms]; client=[127.0.0.1]; method=[POST]; servlet=[measurementplanning]; session=[null]; user=[null]; status=[OK]>
What i doing wrong ... ?
Anyone can help ? :?
Thanks ...