IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Web Java Discussion :

[Spring MVC] onSubmit n'est pas éxecuté


Sujet :

Spring Web Java

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2005
    Messages : 163
    Points : 86
    Points
    86
    Par défaut [Spring MVC] onSubmit n'est pas éxecuté
    Salut,
    je voulais savoir pq ma méthode onSubmit ne s'execute pas, quand je clique sur le bouton envoyer de ma JSP il ya rien qui se passe

    voila mon controleur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    package istia.st.springmvc.personnes.web;
     
    import java.text.SimpleDateFormat;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
     
    import istia.st.springmvc.personnes.dao.DaoException;
    //import istia.st.springmvc.personnes.entites.Personne;
    import istia.st.springmvc.personnes.hibernate.Personnes;
    import istia.st.springmvc.personnes.service.IService;
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import org.springframework.beans.propertyeditors.CustomDateEditor;
    import org.springframework.validation.BindException;
    import org.springframework.validation.Errors;
    import org.springframework.validation.ObjectError;
    import org.springframework.web.bind.RequestUtils;
    import org.springframework.web.bind.ServletRequestDataBinder;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
     
    public class EditPersonne extends SimpleFormController {
    	// service
    	IService service;
     
    	public IService getService() {
    		return service;
    	}
     
    	public void setService(IService service) {
    		this.service = service;
    	}
     
    	// enregistrement d'éditeurs de propriétés
    	protected void initBinder(HttpServletRequest request,
    			ServletRequestDataBinder binder) throws Exception {
    		// format attendu pour la date de naissance
    		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    		// format strict
    		dateFormat.setLenient(false);
    		// on enregistre un éditeur de propriétés String (dd/MM/yyyy) -> Date
    		// CustomDateEditor est fourni par Spring - il sera utilisé par Spring
    		// pour transformer
    		// la chaîne saisie dans le formulaire en type java.util.Date
    		// la date ne pourra être vide (2ième paramètre de CustomDateEditor)
    		binder.registerCustomEditor(java.util.Date.class, null,
    				new CustomDateEditor(dateFormat, false));
    	}
     
    	// préparation [Personne] à afficher
    	protected Object formBackingObject(HttpServletRequest request) {
    		System.out.println("[EditPersonne] formBakingObject **************************************");
    		// on récupère l'id de la personne
    		int id = RequestUtils.getIntParameter(request, "id", -1);
    		// ajout ou modification ?
    		Personnes personne = null;
    		if (id != -1) {
    			// modification - on récupère la personne à modifier
    			personne = service.getOne(id);
    		}else{
    			// ajout - on crée une personne vide
    			personne = new Personnes();
    			personne.setId(-1);
    		}
    		// on rend l'objet [Personne]
    		return personne;
    	}
     
    	// exécution de la commande
    	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    		// sauvegarde la personne ajoutée ou modifiée
    		System.out.println("[EditPersonne] onSubmit **************************************");
    		Personnes personne = (Personnes) command;
    		int idPersonne = personne.getId();
    		try {
    			// sauvegarde de la personne
    			service.saveOne(personne);
    			// on redirige vers la liste des personnes
    			return new ModelAndView("r-list");
    		} catch (DaoException ex) {
    			// on note l'erreur
    			String message=idPersonne==-1 ? "personne.ajout.echec" : "personne.modification.echec";
    			errors.reject(message,new Object[]{ex.getMessage()},"Echec de la mise à jour: {0}");
    			// on réaffiche le formulaire
    			return showForm(request,response, errors);
    		}
    	}
     
    	/*protected Map referenceData(HttpServletRequest request, Object model, Errors errors) throws Exception {
    		Map data = new HashMap();
    		data.putAll(super.referenceData(request, model, errors));
     
    		if (errors.hasErrors()) {
     
    			System.out.println("Errors found.....................");
     
    			for (Iterator iter = errors.getAllErrors().iterator(); iter.hasNext();){
    				ObjectError error = (ObjectError) iter.next();
     
    				System.out.println("ERROR: " + error.getDefaultMessage());
    			}
     
    		}	
     
    	        return data;
    	}
    	 */
    }
    mon fichier personnes-servlet.xml est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<!-- les mappings de l'application-->
    	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/list.html">Personnes.ListController</prop>
    				<prop key="/delete.html">Personnes.DeleteController</prop>
    				<prop key="/edit.html">Personnes.EditController</prop>
    			</props>
    		</property>
    	</bean>
     
    	<bean name="openSessionInViewInterceptor"  
        class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
           <property name="sessionFactory"><ref bean="sessionFactory"/></property>
      	</bean>
     
    	<!-- LES CONTROLEURS -->
    	<bean id="Personnes.ListController" 
    		class="istia.st.springmvc.personnes.web.ListPersonnes">
    		<property name="service">
    			<ref bean="service"/>
    			<!-- <ref bean="Personnes.ListController"/> -->
    		</property>
    	</bean>
    	<bean id="Personnes.DeleteController" 
    		class="istia.st.springmvc.personnes.web.DeletePersonne">
    		<property name="service">
    			<ref bean="service"/>
    			<!--   <ref bean="Personnes.DeleteController"/> -->
    		</property>
    	</bean>
    	<bean id="Personnes.EditController" 
    		class="istia.st.springmvc.personnes.web.EditPersonne">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>personne</value>
    		</property>
    		<property name="validator">
    			<ref bean="Personnes.Validator"/>
    		</property>
    		<property name="formView">
    			<value>edit</value>
    		</property>
    		<property name="service">
    			<ref bean="service"/>
    			<!--   <ref bean="Personnes.EditController"/> -->
    		</property>
    	</bean>
    	<!-- le validateur -->
    	<bean id="Personnes.Validator" 
    		class="istia.st.springmvc.personnes.web.ValidatePersonne"/>
    	<!-- le résolveur de vues -->
    	<bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    		<property name="basename">
    			<value>vues</value>
    		</property>
    	</bean>
    	<!-- le gestionnaire d'exceptions -->
    	<bean
    		class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    		<property name="exceptionAttribute">
    			<value>exception</value>
    		</property>
    		<property name="defaultStatusCode">
    			<value>200</value>
    		</property>
    		<property name="defaultErrorView">
    			<value>exception</value>
    		</property>
    	</bean>
    	<!-- le fichier des messages -->
    	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename">
    			<value>messages</value>
    		</property>
    	</bean>
    </beans>
    et enfin voila le log de tomcat, vous allez trouver des messages dedans c'est moi qui les affichent pour suivre l'execution du programme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    Root WebApplicationContext: initialization started
     INFO [http-8081-Processor25] - Loading Spring root WebApplicationContext
     INFO [http-8081-Processor25] - JDK 1.4+ collections available
     INFO [http-8081-Processor25] - Commons Collections 3.x available
     INFO [http-8081-Processor25] - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
     INFO [http-8081-Processor25] - Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,myTransactionManager,hibernateInterceptor,myPersonneDao,service]; root of BeanFactory hierarchy
     INFO [http-8081-Processor25] - 6 beans defined in application context [Root WebApplicationContext]
     INFO [http-8081-Processor25] - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@258c74]
     INFO [http-8081-Processor25] - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1285252]
     INFO [http-8081-Processor25] - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@34a1c8]
     INFO [http-8081-Processor25] - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,myTransactionManager,hibernateInterceptor,myPersonneDao,service]; root of BeanFactory hierarchy]
     INFO [http-8081-Processor25] - Loaded JDBC driver: com.mysql.jdbc.Driver
     INFO [http-8081-Processor25] - Hibernate 3.2.4.sp1
     INFO [http-8081-Processor25] - hibernate.properties not found
     INFO [http-8081-Processor25] - Bytecode provider name : cglib
     INFO [http-8081-Processor25] - using JDK 1.4 java.sql.Timestamp handling
    ERROR [http-8081-Processor25] - Don't use old DTDs, read the Hibernate 3.x Migration Guide!
     INFO [http-8081-Processor25] - Mapping class: istia.st.springmvc.personnes.hibernate.Personnes -> personnes
     INFO [http-8081-Processor25] - Building new Hibernate SessionFactory
     INFO [http-8081-Processor25] - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
     INFO [http-8081-Processor25] - RDBMS: MySQL, version: 4.1.9-max
     INFO [http-8081-Processor25] - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.9 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
     INFO [http-8081-Processor25] - Using dialect: org.hibernate.dialect.MySQLDialect
     INFO [http-8081-Processor25] - Using default transaction strategy (direct JDBC transactions)
     INFO [http-8081-Processor25] - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
     INFO [http-8081-Processor25] - Automatic flush during beforeCompletion(): disabled
     INFO [http-8081-Processor25] - Automatic session close at end of transaction: disabled
     INFO [http-8081-Processor25] - JDBC batch size: 15
     INFO [http-8081-Processor25] - JDBC batch updates for versioned data: disabled
     INFO [http-8081-Processor25] - Scrollable result sets: enabled
     INFO [http-8081-Processor25] - JDBC3 getGeneratedKeys(): enabled
     INFO [http-8081-Processor25] - Connection release mode: on_close
     INFO [http-8081-Processor25] - Maximum outer join fetch depth: 2
     INFO [http-8081-Processor25] - Default batch fetch size: 1
     INFO [http-8081-Processor25] - Generate SQL with comments: disabled
     INFO [http-8081-Processor25] - Order SQL updates by primary key: disabled
     INFO [http-8081-Processor25] - Order SQL inserts for batching: disabled
     INFO [http-8081-Processor25] - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
     INFO [http-8081-Processor25] - Using ASTQueryTranslatorFactory
     INFO [http-8081-Processor25] - Query language substitutions: {}
     INFO [http-8081-Processor25] - JPA-QL strict compliance: disabled
     INFO [http-8081-Processor25] - Second-level cache: enabled
     INFO [http-8081-Processor25] - Query cache: disabled
     INFO [http-8081-Processor25] - Cache provider: org.hibernate.cache.NoCacheProvider
     INFO [http-8081-Processor25] - Optimize cache for minimal puts: disabled
     INFO [http-8081-Processor25] - Structured second-level cache entries: disabled
     INFO [http-8081-Processor25] - Statistics: disabled
     INFO [http-8081-Processor25] - Deleted entity synthetic identifier rollback: disabled
     INFO [http-8081-Processor25] - Default entity-mode: pojo
     INFO [http-8081-Processor25] - Named query checking : enabled
     INFO [http-8081-Processor25] - building session factory
     INFO [http-8081-Processor25] - Not binding factory to JNDI, no JNDI name configured
     INFO [http-8081-Processor25] - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@101e081] of Hibernate SessionFactory for HibernateTransactionManager
     INFO [http-8081-Processor25] - Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for root WebApplicationContext
     INFO [http-8081-Processor25] - Root WebApplicationContext: initialization completed in 3024 ms
     INFO [http-8081-Processor25] - Initializing servlet 'personnes'
     INFO [http-8081-Processor25] - FrameworkServlet 'personnes': initialization started
     INFO [http-8081-Processor25] - Loading WebApplicationContext for Spring FrameworkServlet 'personnes'
     INFO [http-8081-Processor25] - Loading XML bean definitions from ServletContext resource [/WEB-INF/personnes-servlet.xml]
     INFO [http-8081-Processor25] - Bean factory for application context [WebApplicationContext for namespace 'personnes-servlet']: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping,openSessionInViewInterceptor,Personnes.ListController,Personnes.DeleteController,Personnes.EditController,Personnes.Validator,org.springframework.web.servlet.view.ResourceBundleViewResolver,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver,messageSource]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,myTransactionManager,hibernateInterceptor,myPersonneDao,service]; root of BeanFactory hierarchy
     INFO [http-8081-Processor25] - 9 beans defined in application context [WebApplicationContext for namespace 'personnes-servlet']
     INFO [http-8081-Processor25] - Using MessageSource [org.springframework.context.support.ResourceBundleMessageSource: basenames=[messages]]
     INFO [http-8081-Processor25] - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@86d597]
     INFO [http-8081-Processor25] - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.DelegatingThemeSource@30b601]
     INFO [http-8081-Processor25] - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping,openSessionInViewInterceptor,Personnes.ListController,Personnes.DeleteController,Personnes.EditController,Personnes.Validator,org.springframework.web.servlet.view.ResourceBundleViewResolver,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver,messageSource]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,myTransactionManager,hibernateInterceptor,myPersonneDao,service]; root of BeanFactory hierarchy]
     INFO [http-8081-Processor25] - Default error view is 'exception'
     INFO [http-8081-Processor25] - Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for servlet 'personnes'
     INFO [http-8081-Processor25] - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided
     INFO [http-8081-Processor25] - Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@1d753b7]
     INFO [http-8081-Processor25] - Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@1b93526]
     INFO [http-8081-Processor25] - No HandlerAdapters found in servlet 'personnes': using default
     INFO [http-8081-Processor25] - FrameworkServlet 'personnes': initialization completed in 220 ms
     INFO [http-8081-Processor25] - Servlet 'personnes' configured successfully
    [ServiceImpl] getAll **************************************
    [DaoImplCommon] getAll ******************************************** 
     INFO [http-8081-Processor25] - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
     INFO [http-8081-Processor25] - SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
    [ListPersonne] handleRequest*********************************
     WARN [http-8081-Processor25] - Use of 'class' property in [org.springframework.beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'
     WARN [http-8081-Processor25] - Use of 'class' property in [org.springframework.beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'
     WARN [http-8081-Processor25] - Use of 'class' property in [org.springframework.beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'
     WARN [http-8081-Processor25] - Use of 'class' property in [org.springframework.beans.factory.support.PropertiesBeanDefinitionReader] is deprecated in favor of '(class)'
     INFO [http-8081-Processor25] - 4 beans defined in application context [org.springframework.web.context.support.GenericWebApplicationContext;hashCode=3393419]
     INFO [http-8081-Processor25] - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@171b246]
     INFO [http-8081-Processor25] - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@16f4ce0]
     INFO [http-8081-Processor25] - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.DelegatingThemeSource@201d6d]
     INFO [http-8081-Processor25] - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [list,exception,r-list,edit]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping,openSessionInViewInterceptor,Personnes.ListController,Personnes.DeleteController,Personnes.EditController,Personnes.Validator,org.springframework.web.servlet.view.ResourceBundleViewResolver,org.springframework.web.servlet.handler.SimpleMappingExceptionResolver,messageSource]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,sessionFactory,myTransactionManager,hibernateInterceptor,myPersonneDao,service]; root of BeanFactory hierarchy]
    [EditPersonne] formBakingObject **************************************
     INFO [http-8081-Processor25] - Theme created: name 'theme', basename [theme]
     INFO [http-8081-Processor25] - Using JSP 2.0 ExpressionEvaluator
    Merci

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    163
    Détails du profil
    Informations personnelles :
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2005
    Messages : 163
    Points : 86
    Points
    86
    Par défaut
    Salut,
    enfin j'ai trouvé le probleme pas tout seul biensur. j'avais une exception qui se lever mais que je voyais pas, il a fallut redifinir la methode referenceData de SimpleFormController pour afficher ces erreurs.

    Bonne chance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. onsubmit n'est pas lancé si la valeur dans input est sélectionnée
    Par kiki91 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 04/05/2015, 09h28
  2. [Spring MVC] onSubmit n'est pas exécuté
    Par napol1fr dans le forum Spring Web
    Réponses: 1
    Dernier message: 30/05/2008, 12h03
  3. [Spring MVC] taglib spring:bind qui ne binde pas
    Par Mohicane dans le forum Spring Web
    Réponses: 2
    Dernier message: 23/01/2008, 13h51
  4. [Spring MVC],[<form:input] pas de binding !
    Par Invité dans le forum Spring Web
    Réponses: 4
    Dernier message: 20/12/2007, 16h44
  5. [Spring MVC][Validator] Ne stop pas si il y a une erreurs
    Par Hikage dans le forum Spring Web
    Réponses: 3
    Dernier message: 15/02/2006, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo