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] et formulaire


Sujet :

Spring Web Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    130
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 130
    Points : 68
    Points
    68
    Par défaut [Spring MVC] et formulaire
    Bonjour
    Je veux avec Spring crée un formulaire (tres simple pour commencer juste un champ texte par exemple) et je ne sais pas trop comment faire pour que mon fichier srpingapp-servlet.xml passe les valeur a mon controlleur??
    Qui a la solution??

  2. #2
    Rédacteur
    Avatar de Hikage
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    1 177
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : Belgique

    Informations forums :
    Inscription : Mai 2004
    Messages : 1 177
    Points : 6 301
    Points
    6 301
    Par défaut
    j'ai cru lire que tu avais acheté Spring par la pratique dans un autre post, donc je me permet de te conseille de le lire avant de te lancer dans du development Spring.

    Il est très bien fait, et l'application de référence est très bien aussi, je te conseile donc de regarder un peu le code de celle-ci aussi, et essayer de comprendre comment cela fonctionne.

    Ensuite pour Spring MVC, Serge Tahé à ecrit de très bon article ici meme :


    Il y a a aussi un petit guide sur le site de Spring : http://www.springframework.org/docs/...ep-Part-1.html

    Ceux-ci devrait t'aider à mieux comprendre le framework Web de Spring.

    Je te souhaite une bonne lecture, et si après cela, tu as d'autre questions, n'hésite pas à revenir ici.
    Mais il est nettement plus intéressant de comprendre par soit meme via la lecture d'article, et par des test simple.

    J'ai eu un peu de mal au début aussi, j'ai parfois été bloqué pendant 1h sur des "bete" problèmes, mais le fait d'avoir réussi à les resoudre seul m'a apporté bcp !

    Courage :-)
    Hikage
    SCJP / SCWCD & SCWSJD Certified / Spring Framework Certified
    [Personal Web] [CV]

    F.A.Q Spring Framework - Participez !

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    130
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 130
    Points : 68
    Points
    68
    Par défaut
    Je vais regarder dans le bouquin que j'ai pris si il y a un exemple clair car la je patoge mais si quelqu'un a un exemple je suis prenneur
    merci

  4. #4
    Membre émérite
    Avatar de Nesmontou
    Homme Profil pro
    Architecte logiciel
    Inscrit en
    Septembre 2004
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Architecte logiciel
    Secteur : Finance

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 612
    Points : 2 969
    Points
    2 969
    Par défaut
    Salut, tu peux aussi jeter un oeil sur le site de Spring, il y a un petit tuto et la 3ème partie explique comment mettre en place un formulaire : http://www.springframework.org/docs/...ep-Part-3.html

    Bon développement
    Si vous ne pouvez expliquer un concept à un enfant de six ans, c'est que vous ne le comprenez pas complètement. Albert EINSTEIN

    F.A.Q. : Java, PHP, (X)HTML / CSS

    N'oubliez pas de cliquer sur le bouton Résolu en bas de page quand vous avez obtenu une solution à votre problème

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    130
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 130
    Points : 68
    Points
    68
    Par défaut
    J'ai essayer avec le tuto
    voila mon pb

    voici mon springaap-servlet.xml
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 'http://www.springframework.org/dtd/spring-beans.dtd'>
     
     
    <beans>
    	<bean id="livre" class="livre.Livre">
    		<property name="id">
    			<value>1</value>
    		</property>
    		<property name="nom">
    			<value>nom</value>
    		</property>
    		<property name="auteur">
    			<value>auteur</value>
    		</property>
    	</bean>
     
    	<bean id="controller" class="web.SpringappController">
    		<property name="livre">
    			<ref bean="livre" />
    		</property>
    		<property name="livreMan">
    			<ref bean="livreServiceTarget" />
    		</property>
    	</bean>
     
     
    	<bean id="urlMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<!-- 				<prop key="/hello.htm">controller</prop>-->
    				<prop key="/hello.htm">fomulaireappController</prop>
    			</props>
    		</property>
     
    	</bean>
     
     
     
    	<!-- ========================= Start of PERSISTENCE DEFINITIONS =========================-->
     
    	<!-- DataSource Definition -->
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName">
    			<value>com.mysql.jdbc.Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc:mysql://localhost:3306/bdtest</value>
    		</property>
    		<property name="username">
    			<value>root</value>
    		</property>
    		<property name="password">
    			<value>root</value>
    		</property>
    	</bean>
     
    	<!-- Hibernate SessionFactory Definition -->
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="mappingResources">
    			<list>
    				<value>livre/livre.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					org.hibernate.dialect.MySQLDialect
    				</prop>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.cglib.use_reflection_optimizer">
    					true
    				</prop>
    				<prop key="hibernate.cache.provider_class">
    					org.hibernate.cache.HashtableCacheProvider
    				</prop>
    			</props>
    		</property>
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    	</bean>
     
    	<!-- Spring Data Access Exception Translator Defintion -->
    	<bean id="jdbcExceptionTranslator"
    		class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    	</bean>
     
    	<!-- Hibernate Template Defintion -->
    	<bean id="hibernateTemplate"
    		class="org.springframework.orm.hibernate3.HibernateTemplate">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    		<property name="jdbcExceptionTranslator">
    			<ref bean="jdbcExceptionTranslator" />
    		</property>
    	</bean>
     
    	<!-- Hibernate Transaction Manager Definition -->
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
     
    	<!-- ========================= Start of DAO DEFINITIONS ========================= -->
     
    	<!-- TODO DAO Definition: Hibernate implementation -->
    	<bean id="livreDaoAble" class="livre.dao.LivreDaoImpl">
    		<property name="hibernateTemplate">
    			<ref bean="hibernateTemplate" />
    		</property>
    	</bean>
    	<!-- ========================= Start of SERVICE DEFINITIONS ========================= -->
     
    	<!-- TODO Service Definition -->
    	<bean id="livreServiceTarget" class="livre.LivreServiceImpl">
    		<property name="livreDao">
    			<ref local="livreDaoAble" />
    		</property>
    	</bean>
     
    	<!-- Transactional proxy for the TODO Service -->
    	<bean id="livreService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref local="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="livreServiceTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="save*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
     
    	<!--  Formulaire -->
    	<!--  Validator and Form Controller for the "Price Increase" page -->
    	<bean id="personneValidator" class="form.PersonneValidator" />
    	<bean id="fomulaireappController"
    		class="web.FormulaireappController">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandName">
    			<value>personne</value>
    		</property>
    		<property name="commandClass">
    			<value>form.Personne</value>
    		</property>
    		<property name="validator">
    			<ref bean="personneValidator" />
    		</property>
    		<property name="formView">
    			<value>personne</value>
    		</property>
    		<property name="successView">
    			<value>hello.htm</value>
    		</property>
    		<property name="personne">
    			<ref bean="personne" />
    		</property>
    	</bean>
     
    <!-- 
    	<bean id="personne" class="form.Personne">
    		<property name="nom">
    			<value>nom</value>
    		</property>
    	</bean>
     -->
     
    </beans>
    voici mon controlleur
    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
    package web;
     
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
     
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    import org.springframework.web.servlet.view.RedirectView;
     
    import form.Personne;
    import form.PersonneValidator;
     
    public class FormulaireappController extends SimpleFormController
    {
    	/** Logger for this class and subclasses */
    	protected final Log logger = LogFactory.getLog(getClass());
     
    	private Personne personne;
     
    	private PersonneValidator personneValidator;
     
    	public PersonneValidator getPersonneValidator()
    	{
    		return personneValidator;
    	}
     
    	public void setPersonneValidator(PersonneValidator personneValidator)
    	{
    		System.out.println("setPersonneValidator");
    		this.personneValidator = personneValidator;
    	}
     
    	public ModelAndView onSubmit(Object command)throws ServletException 
        {
     
    		//int increase = ((PriceIncrease) command).getPercentage();
    		String toto = ((Personne)command).getNom(); 
     
    		System.out.println("onSubmit "+ toto);
    		logger.info("Passage dans FomulaireappControler");
    		System.out.println(toto);
    		//prodMan.increasePrice(increase);
     
    //		String now = (new java.util.Date()).toString();
    		logger.info("returning from PriceIncreaseForm view to " + getSuccessView());
     
    		return new ModelAndView(new RedirectView(getSuccessView()));
     
        }
     
    	protected Object formBackingObject(HttpServletRequest request)
    			throws ServletException
    	{
    		Personne toto = new Personne();
    		System.out.println("formBacking");
    		toto.setNom("non");
     
    		return toto;
     
    	}
     
    	public Personne getPersonne()
    	{
    		System.out.println("getPersonne");
    		return personne;
    	}
     
    	public void setPersonne(Personne nom)
    	{
    		System.out.println("setPersonne " + nom);
    		this.personne = nom;
    	}
     
     
    }
    Il me met l'erreur suivante
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    La ressource demandée (/MySpringWebapps/personne) n'est pas disponible.
    Je ne vois pas d'ou sa vient
    qui a une idee

  6. #6
    Membre actif Avatar de coco62
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    237
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 237
    Points : 278
    Points
    278
    Par défaut
    Je suppose que ce message vient de ton browser

    2 solutions:
    1) probleme de webapp:
    2) probleme Spring

    Pour regarder le point 1, vérifie que tu accède bien à des ressourses sous ta racine de contexte.

    http://..../MySpringWebapps/welcome.html

    Si c'est OK, merci de founir le web.xml de ton appli

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    130
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2007
    Messages : 130
    Points : 68
    Points
    68
    Par défaut
    voici le web.xml je n'ai pas eu le temps de regarder encore je te tient au courant
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
     
    <web-app>
    	<context-param>
    		<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    		<param-value>messages</param-value>
    	</context-param>
      <servlet>
        <servlet-name>springapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
     
      <servlet-mapping>
        <servlet-name>springapp</servlet-name>
        <url-pattern>*.htm</url-pattern>
      </servlet-mapping>
     
      <welcome-file-list>
        <welcome-file>
              index.jsp
        </welcome-file>
      </welcome-file-list>
     
      <taglib>
        <taglib-uri>/spring</taglib-uri>
        <taglib-location>/WEB-INF/spring.tld</taglib-location>
      </taglib>
     
    </web-app>

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

Discussions similaires

  1. Spring MVC + JSP : Formulaire avec 3 boutons submit
    Par JQueen dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 04/11/2014, 12h48
  2. Spring MVC redirect formulaire
    Par Ho(c)ine. dans le forum Spring Web
    Réponses: 1
    Dernier message: 12/05/2009, 16h14
  3. [Spring MVC] Deux formulaires sur une même page
    Par djodjo dans le forum Spring Web
    Réponses: 1
    Dernier message: 20/10/2008, 09h52
  4. [Spring MVC] Gros formulaire Web
    Par Invité dans le forum Spring Web
    Réponses: 3
    Dernier message: 19/02/2008, 09h20
  5. [Spring MVC] Problème formulaire avec Collection
    Par arN34 dans le forum Spring Web
    Réponses: 1
    Dernier message: 16/09/2006, 13h17

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