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

Servlets/JSP Java Discussion :

supprimer un élément d'une base affiché dans une jsp


Sujet :

Servlets/JSP Java

  1. #1
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut supprimer un élément d'une base affiché dans une jsp
    Bonjour
    Je travaille SOA avec Hibernate et Spring.
    Je voudrais supprimer avec u bouton dans une jsp un employé par exemple qui est affiché dans un tableau:

    voici mon service: EmployeDAOImpl:
    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
    @Override
    	public void createEmploye(Employes employe) {
     
    		hibernateTemplate.saveOrUpdate(employe);
     
    	}
     
    	@Override
    	@SuppressWarnings("unchecked")
    	public List<Employes> findallEmploye() {
     
    		employeList= hibernateTemplate.find("from Employes");
    		return employeList;
    	}
     
    	@Override
    	public void deleteEmploye(int idEmp) {
    		Employes employe=(Employes)hibernateTemplate.get(Employes.class,idEmp);	
    		hibernateTemplate.delete(employe);
     
    	}
    controllers:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    public class EmployeControllerAdd extends MultiActionController {
     
    	private EmployeDAO employeDAO;
     
    	public void setEmployeDAO(EmployeDAO employeDAO) {
    		this.employeDAO = employeDAO;
    	}
     
    	public ModelAndView add(HttpServletRequest request,
    			HttpServletResponse response, Employes employe) throws Exception {
    		employeDAO.createEmploye(employe);
    		return new ModelAndView("redirect:list.htm");
    	}
    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
    public class EmployeControllerDelete extends MultiActionController {
     
    	private EmployeDAO employeDAO;
    	private int idEmp;
     
    	public void setEmployeDAO(EmployeDAO employeDAO) {
    		this.employeDAO = employeDAO;
    	}
     
    	public void setidEmp(int  idEmp) {
    		this.idEmp = idEmp;
    	}
     
    	public ModelAndView delete(HttpServletRequest request,
    			HttpServletResponse response, int idEmp) throws Exception {
     
     
    		employeDAO.deleteEmploye(idEmp);
     
    		return new ModelAndView("redirect:list.htm");
    	}
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    public ModelAndView list(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		ModelMap modelMap = new ModelMap();
    		modelMap.addAttribute("employeList", employeDAO.findallEmploye());
    		modelMap.addAttribute("employe", new Employes());
    		return new ModelAndView("employeForm", modelMap);
    	}
    mon employeForm.jsp

    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
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <style type="text/css">
    .even {
            background-color: silver;
    }
    </style>
    <title>Registration Page</title>
    </head>
    <body>
     
     <center> <h1>Ajouter un Employe</h1> </center> 
     
    <form:form action="add.htm" commandName="employe">
    	<table>
     
    		<tr>
    			<td>Nom :</td>
    			<td><form:input path="firstame" /></td>
    		</tr>
     
    		<tr>
    			<td>Prenom:</td>
    			<td><form:input path="lastname" /></td>
    		</tr>
    		<tr>
    			<td>mail:</td>
    			<td><form:input path="mail" /></td>
    		</tr>
    		<tr>
    			<td>job:</td>
    			<td><form:input path="function" /></td>
    		</tr>
    		<tr>
    			<td>fiche:</td>
    			<td><form:input path="sheet" /></td>
    		</tr>
     
    	<tr>
    			<td>RIB:</td>
    			<td><form:input path="rib" /></td>
    		</tr>
    		<tr>
    			<td>situation maritale:</td>
    			<td><form:input path="maritalStatus" /></td>
    		</tr>
     
    	<tr>
    			<td>Nombre des enfants :</td>
    			<td><form:input path="numberOfChildren" /></td>
    		</tr>
     
    		<tr>
    			<td colspan="2"><input type="submit" value="Register"></td>
    		</tr>
    	</table>
    </form:form>
     
     
     
    <c:if test="${fn:length(employeList)> 0}">
    	<table cellpadding="5">
    		<tr class="even">
     
    			<th>prenom</th>
    			<th>nom</th>
    			<th>mail</th>
    			<th>job</th>
    			<th>fiche</th>
    			<th>RIB</th>
    			<th>situation maritale</th>
    			<th>Nombre des enfants</th>
    		</tr>
     
    		<form:form action="delete.htm" commandName="employe">
     
    		<c:forEach items="${employeList}" var="employe" varStatus="status">
    			<tr class="<c:if test="${status.count % 2 == 0}">even</c:if>">
     
    				<td>${employe.firstame}</td>
    				<td>${employe.lastname}</td>
    				<td>${employe.mail}</td>
    				<td>${employe.function}</td>
    				<td>${employe.sheet}</td>
    				<td>${employe.rib}</td>
    				<td>${employe.maritalStatus}</td>
    				<td>${employe.numberOfChildren}</td>
     
    			<td height="28" colspan="5" bgcolor="#99B1CC">
     
    		</td>
     
            <td><a href="<c:url value="delete.htm?idEmp=${employe.idemployees}"/>">Supprimer</a></td>
            <td><a href="<c:url value="/do/edit?id=${personne.id}"/>">Modifier</a></td>
    			</tr>
     
    		</c:forEach>
    	 </form:form>	 
    	</table>
    </c:if>
     <a href="<c:url value="/accueil.htm"/>">Home</a>
    </body>
    </html>
    programmation du bouton pour la suppression:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <td><a href="<c:url value="delete.htm?idEmp=${employe.idemployees}"/>">Supprimer</a></td>
            <td><a href="<c:url value="/do/edit?id=${personne.id}"/>">Modifier</a></td>

    mais ça n'a pas marché
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [int]: No default constructor found; nested exception is java.lang.NoSuchMethodException: int.<init>()
    	org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:81)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.newCommandObject(MultiActionController.java:521)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:468)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    J'ai passé une journée à essayer de faire marcher ce simple bouton mais envain!

    pourriez vous m'aider?

  2. #2
    Membre Expert
    Homme Profil pro
    Dév. Java & C#
    Inscrit en
    Octobre 2002
    Messages
    1 414
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Dév. Java & C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 414
    Par défaut
    Bonjour,

    No default constructor found; nested exception is java.lang.NoSuchMethodException: int.<init>()
    Il faut toujours lire consciencieusement les messages d'erreur

    Je ne sais pas de quel bean il s'agit. Je suppose que la classe EmployeDAO n'a pas de constructeur par défaut.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    public class EmployeDAO implements ParentDAO {
     
       public EmployeDAO {
          super();
       }
    }

  3. #3
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    Citation Envoyé par jowo Voir le message
    Bonjour,



    Il faut toujours lire consciencieusement les messages d'erreur

    Je ne sais pas de quel bean il s'agit. Je suppose que la classe EmployeDAO n'a pas de constructeur par défaut.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    public class EmployeDAO implements ParentDAO {
     
       public EmployeDAO {
          super();
       }
    }

    EmployeDAO n'est pas une classe mais interface
    et son implémentation c'est EmployeDAOImpl
    voici le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    package com.proxymit.grh.service.interf;
     
    import java.util.List;
     
    import com.proxymit.grh.model.Employes;
     
    public interface EmployeDAO {
     
     
    		public List<Employes> findallEmploye(); // liste des congés
    	    public void createEmploye(Employes employe);   
    		void deleteEmploye(int idEmp);
     
    }
    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
    package com.proxymit.grh.service.interfImpl;
    import java.util.List;
    import org.hibernate.SessionFactory;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import com.proxymit.grh.model.Employes;
     
    import com.proxymit.grh.service.interf.EmployeDAO;
     
     
    public class EmployeDAOImpl implements EmployeDAO {
     
    	public EmployeDAOImpl(){
    		super();
    	}
     
     
    	private static List<Employes> employeList;
    	private HibernateTemplate hibernateTemplate;
     
    	public void setSessionFactory(SessionFactory sessionFactory) {
     
    		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    	}
     
    	@Override
    	public void createEmploye(Employes employe) {
     
    		hibernateTemplate.saveOrUpdate(employe);
     
    	}
     
    	@Override
    	@SuppressWarnings("unchecked")
    	public List<Employes> findallEmploye() {
     
    		employeList= hibernateTemplate.find("from Employes");
    		return employeList;
    	}
     
    	@Override
    	public void deleteEmploye(int idEmp) {
    		Employes employe=(Employes)hibernateTemplate.get(Employes.class,idEmp);	
    		hibernateTemplate.delete(employe);
     
    	}
     
    }
    Mon objet persistant
    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
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    package com.proxymit.grh.model;
     
    // Generated 17 mars 2010 11:47:29 by Hibernate Tools 3.2.4.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import static javax.persistence.GenerationType.IDENTITY;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
     
    /**
     * Employes generated by hbm2java
     */
    @Entity
    @Table(name = "employes", catalog = "proxym")
    public class Employes implements java.io.Serializable {
     
    	private int idemployees;
    	private String firstame;
    	private String lastname;
    	private String mail;
    	private String function;
    	private String sheet;
    	private int rib;
    	private String maritalStatus;
    	private int numberOfChildren;
     
     
     
     
    	public Employes() {
    		super();
    	}
     
     
     
    	public Employes(int idemployees) {
    		 setIdemployees(getIdemployees());
    	}
     
     
    	public Employes(String firstame, String lastname, String mail,
    			String function) {
    		this.firstame = firstame;
    		this.lastname = lastname;
    		this.mail = mail;
    		this.function = function;
    	}
     
     
     
    	public Employes( String firstame, String lastname,
    			String mail, String function, String sheet, int rib,
    			String maritalStatus, int numberOfChildren) {
     
     
     
     
    		this.firstame = firstame;
    		this.lastname = lastname;
    		this.mail = mail;
    		this.function = function;
    		this.sheet = sheet;
    		this.rib = rib;
    		this.maritalStatus = maritalStatus;
    		this.numberOfChildren = numberOfChildren;
     
     
     
    	}
     
    	public Employes(int idemployees, String firstame, String lastname,
    			String mail, String function, String sheet, int rib,
    			String maritalStatus, int numberOfChildren) {
    			 setLastname(lastname);
    			 setFirstame(firstame);
    			 setMail(mail);
    			 setFunction(function);
    			 setSheet(sheet);
    			 setNumberOfChildren(numberOfChildren);
    			 setMaritalStatus(maritalStatus);
    			 setRib(rib);
    			 setIdemployees(idemployees);
     
    			 }
     
     
    	public Employes(Employes employe) {
    			 setLastname(getLastname());
    			 setFirstame( getFirstame());
    			 setMail(getMail());
    			 setFunction(getFunction());
    			 setSheet(getSheet());
    			 setNumberOfChildren( getNumberOfChildren());
    			 setMaritalStatus(getMaritalStatus());
    			 setRib(getRib());
    			 setIdemployees(getIdemployees());
     
    			 }
     
    	/*public Employes( Integer idemployees, String firstame, String lastname,
    			String mail, String function, String sheet, Integer rib,
    			String maritalStatus, Integer numberOfChildren) {
    		this.idemployees=idemployees;
    		this.firstame = firstame;
    		this.lastname = lastname;
    		this.mail = mail;
    		this.function = function;
    		this.sheet = sheet;
    		this.rib = rib;
    		this.maritalStatus = maritalStatus;
    		this.numberOfChildren = numberOfChildren;	
    	}*/
     
    	@Id
    	@GeneratedValue(strategy = IDENTITY)
    	@Column(name = "idemployees", unique = true, nullable = false)
    	public int getIdemployees() {
    		return this.idemployees;
    	}
     
    	public void setIdemployees(int idemployees) {
    		this.idemployees = idemployees;
    	}
     
     
     
    	@Column(name = "firstame", nullable = false, length = 45)
    	public String getFirstame() {
    		return this.firstame;
    	}
     
    	public void setFirstame(String firstame) {
    		this.firstame = firstame;
    	}
     
    	@Column(name = "lastname", nullable = false, length = 45)
    	public String getLastname() {
    		return this.lastname;
    	}
     
    	public void setLastname(String lastname) {
    		this.lastname = lastname;
    	}
     
    	@Column(name = "mail", nullable = false, length = 45)
    	public String getMail() {
    		return this.mail;
    	}
     
    	public void setMail(String mail) {
    		this.mail = mail;
    	}
     
    	@Column(name = "function", nullable = false, length = 45)
    	public String getFunction() {
    		return this.function;
    	}
     
    	public void setFunction(String function) {
    		this.function = function;
    	}
     
    	@Column(name = "sheet")
    	public String getSheet() {
    		return this.sheet;
    	}
     
    	public void setSheet(String sheet) {
    		this.sheet = sheet;
    	}
     
    	@Column(name = "rib")
    	public int getRib() {
    		return this.rib;
    	}
     
    	public void setRib(int rib) {
    		this.rib = rib;
    	}
     
    	@Column(name = "MaritalStatus", length = 45)
    	public String getMaritalStatus() {
    		return this.maritalStatus;
    	}
     
    	public void setMaritalStatus(String maritalStatus) {
    		this.maritalStatus = maritalStatus;
    	}
     
    	@Column(name = "number_of_children")
    	public int getNumberOfChildren() {
    		return this.numberOfChildren;
    	}
     
    	public void setNumberOfChildren(int numberOfChildren) {
    		this.numberOfChildren = numberOfChildren;
    	}
     
     
    }

Discussions similaires

  1. [AC-2003] Import depuis une base A dans une Base B
    Par ted the Ors dans le forum VBA Access
    Réponses: 1
    Dernier message: 26/01/2010, 19h59
  2. Réponses: 6
    Dernier message: 13/11/2009, 16h06
  3. [MySQL] Afficher une image stockée dans une base de données
    Par LuckySoft dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 22/04/2006, 12h57
  4. [MySQL] Supprimer une ligne afficher dans une base de donnée
    Par julienchpt dans le forum PHP & Base de données
    Réponses: 31
    Dernier message: 14/10/2005, 15h45
  5. copie d'une table Y d'une base A vers une table X d'une base
    Par moneyboss dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 30/08/2005, 21h24

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