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

Struts 1 Java Discussion :

Problème initialisation formulaire


Sujet :

Struts 1 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut Problème initialisation formulaire
    Bonjour, dans une page j'ai définit les trois actions ajout, modification, suppression, mais lors d'une insértion les zone de saisie gardent les valeurs insérée, pour la modification aussi lorsque je clique sur edit les zone du formulaire d'ajout se remplit par les valeurs de la ligne a modfié(lorsque je clique sur modifier je peux modifier les donnée dans le tableau ou je liste mes clients par exemple), j'aimerais bien que c'est clair !

    ClientAction2 :
    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
    package pre.st;
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import ma.corp.plan.metier.Client;
    import ma.corp.plan.metier.GestMetier;
     
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
     
    public class ClientAction2 extends Action {
     public ActionForward execute(
    		 ActionMapping map, 
    		 ActionForm form, 
    		 HttpServletRequest request, 
    		 HttpServletResponse response) throws Exception {
     
    	 ClientForm cf=(ClientForm)form;
    	 GestMetier gm=new GestMetier();
     
    	 if(cf.getAction().equals("ajouter")){
    		 gm.addClient(cf.getClient().getRaisonSociale(),
    				 cf.getClient().getTel(), 
    				 cf.getClient().getEmail());
    		// cf.setClients(gm.getAllClients());
     
    	 }
    	 else if(cf.getAction().equals("edit")){
    		 cf.setClient(gm.getClient(new Long(cf.getIdClient())));
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("update")){
    		 gm.updateClient2(cf.getClient().getIdClient(), 
    				 cf.getClient().getRaisonSociale(), 
    				 cf.getClient().getEmail(), 
    				 cf.getClient().getTel());
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("delete")){
    		 gm.suppClient(new Long(cf.getIdClient()));
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("chercher")){
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 cf.setClients(gm.getAllClients());
    	return map.findForward("vueClient3");
    }
    }
    Clients3.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
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ page import="ma.corp.plan.metier.*" %>    
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
     <html:errors/>
     <hr/>
     <h3>Clients:</h3>
     <table border="1" width="90%">
      <tr>
       <th>Code</th><th>Raison Sociale</th><th>Tel</th><th>Email</th>
      </tr>
      <html:form action="cli2.do">
       <tr>
        <td></td>
        <td><html:text property="client.raisonSociale"></html:text> </td>
        <td><html:text property="client.tel"></html:text> </td>
        <td><html:text property="client.email"></html:text> </td>
        <td><html:submit property="action" value="ajouter"/></td>
       </tr>
      </html:form>
      <logic:iterate id="cli" name="cfp" property="clients" type="Client">
       <bean:define id="action" name="cfp" property="action"></bean:define>
       <bean:define id="idc" name="cfp" property="idClient"></bean:define>
       <% if((action.equals("edit"))&&(idc.equals(cli.getIdClient()))){ %>
       <html:form action="cli2.do">
       <tr>
        <td><bean:write name="cli" property="idClient"/>
        <html:hidden property="client.idClient"/>
        <td><html:text property="client.raisonSociale"></html:text> </td>
        <td><html:text property="client.tel"></html:text> </td>
        <td><html:text property="client.email"></html:text> </td>
        <td><html:submit property="action" value="update"/></td>
       </tr>
      </html:form>
      <%}else{ %>
       <tr>
        <bean:define id="idc" name="cli" property="idClient"></bean:define>
        <td><bean:write name="cli" property="idClient"/></td>
        <td><bean:write name="cli" property="raisonSociale"/></td>
        <td><bean:write name="cli" property="tel"/></td>
        <td><bean:write name="cli" property="email"/></td>
        <td><a href="cli2.do?action=delete&idClient=<%=idc %>">Supp</a></td>
        <td><a href="cli2.do?action=edit&idClient=<%=idc %>">edit</a></td>
       </tr>
       <%} %>
      </logic:iterate>
     </table>
    </body>
    </html>
    Merci pour votre aide !

  2. #2
    Membre confirmé
    Inscrit en
    Juillet 2002
    Messages
    225
    Détails du profil
    Informations forums :
    Inscription : Juillet 2002
    Messages : 225
    Par défaut
    Citation Envoyé par newmar Voir le message
    Bonjour, dans une page j'ai définit les trois actions ajout, modification, suppression, mais lors d'une insértion les zone de saisie gardent les valeurs insérée, pour la modification aussi lorsque je clique sur edit les zone du formulaire d'ajout se remplit par les valeurs de la ligne a modfié(lorsque je clique sur modifier je peux modifier les donnée dans le tableau ou je liste mes clients par exemple), j'aimerais bien que c'est clair !

    ClientAction2 :
    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
    package pre.st;
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import ma.corp.plan.metier.Client;
    import ma.corp.plan.metier.GestMetier;
     
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
     
    public class ClientAction2 extends Action {
     public ActionForward execute(
    		 ActionMapping map, 
    		 ActionForm form, 
    		 HttpServletRequest request, 
    		 HttpServletResponse response) throws Exception {
     
    	 ClientForm cf=(ClientForm)form;
    	 GestMetier gm=new GestMetier();
     
    	 if(cf.getAction().equals("ajouter")){
    		 gm.addClient(cf.getClient().getRaisonSociale(),
    				 cf.getClient().getTel(), 
    				 cf.getClient().getEmail());
    		// cf.setClients(gm.getAllClients());
     
    	 }
    	 else if(cf.getAction().equals("edit")){
    		 cf.setClient(gm.getClient(new Long(cf.getIdClient())));
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("update")){
    		 gm.updateClient2(cf.getClient().getIdClient(), 
    				 cf.getClient().getRaisonSociale(), 
    				 cf.getClient().getEmail(), 
    				 cf.getClient().getTel());
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("delete")){
    		 gm.suppClient(new Long(cf.getIdClient()));
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 else if(cf.getAction().equals("chercher")){
    		 //cf.setClients(gm.getAllClients());
    	 }
    	 cf.setClients(gm.getAllClients());
    	return map.findForward("vueClient3");
    }
    }
    Clients3.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
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ page import="ma.corp.plan.metier.*" %>    
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
     <html:errors/>
     <hr/>
     <h3>Clients:</h3>
     <table border="1" width="90%">
      <tr>
       <th>Code</th><th>Raison Sociale</th><th>Tel</th><th>Email</th>
      </tr>
      <html:form action="cli2.do">
       <tr>
        <td></td>
        <td><html:text property="client.raisonSociale"></html:text> </td>
        <td><html:text property="client.tel"></html:text> </td>
        <td><html:text property="client.email"></html:text> </td>
        <td><html:submit property="action" value="ajouter"/></td>
       </tr>
      </html:form>
      <logic:iterate id="cli" name="cfp" property="clients" type="Client">
       <bean:define id="action" name="cfp" property="action"></bean:define>
       <bean:define id="idc" name="cfp" property="idClient"></bean:define>
       <% if((action.equals("edit"))&&(idc.equals(cli.getIdClient()))){ %>
       <html:form action="cli2.do">
       <tr>
        <td><bean:write name="cli" property="idClient"/>
        <html:hidden property="client.idClient"/>
        <td><html:text property="client.raisonSociale"></html:text> </td>
        <td><html:text property="client.tel"></html:text> </td>
        <td><html:text property="client.email"></html:text> </td>
        <td><html:submit property="action" value="update"/></td>
       </tr>
      </html:form>
      <%}else{ %>
       <tr>
        <bean:define id="idc" name="cli" property="idClient"></bean:define>
        <td><bean:write name="cli" property="idClient"/></td>
        <td><bean:write name="cli" property="raisonSociale"/></td>
        <td><bean:write name="cli" property="tel"/></td>
        <td><bean:write name="cli" property="email"/></td>
        <td><a href="cli2.do?action=delete&idClient=<%=idc %>">Supp</a></td>
        <td><a href="cli2.do?action=edit&idClient=<%=idc %>">edit</a></td>
       </tr>
       <%} %>
      </logic:iterate>
     </table>
    </body>
    </html>
    Merci pour votre aide !
    Salut

    Est-ce que tu as définis une méthode reset() dans ton formBean ?
    tu peux nous donner le code de ton form STP?

  3. #3
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut
    le voila :

    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
    package pre.st;
     
    import java.util.List;
    import java.util.Vector;
     
    import javax.servlet.http.HttpServletRequest;
     
    import ma.corp.plan.metier.Client;
     
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
     
    public class ClientForm extends ActionForm {
    	private long idClient=1;
    	private Client client=new Client();
    	//Pour le liste déroulante
    	private List clients=new Vector();
    	private String action="";
    	public String getAction() {
    		return action;
    	}
    	public void setAction(String action) {
    		this.action = action;
    	}
    	public Client getClient() {
    		return client;
    	}
    	public void setClient(Client client) {
    		this.client = client;
    	}
    	public long getIdClient() {
    		return idClient;
    	}
    	public void setIdClient(long idClient) {
    		this.idClient = idClient;
    	}
    	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
    		ActionErrors errs=new ActionErrors();
    		if(idClient<1){
    		 errs.add("idClient",new ActionError("x.y"));
    		}
    		return errs;
    	}
    	public List getClients() {
    		return clients;
    	}
    	public void setClients(List clients) {
    		this.clients = clients;
    	}
    }

  4. #4
    Membre confirmé
    Inscrit en
    Juillet 2002
    Messages
    225
    Détails du profil
    Informations forums :
    Inscription : Juillet 2002
    Messages : 225
    Par défaut
    Surcharges la méthode reset() dans laqurlle tu initialises tes attributs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public void reset(ActionMapping mapping, HttpServletRequest request){
     
    // tu peux mettre ici une condition sur la nature de ton action 
     //selon ce que  tu veux setter 
     
    getClient().setRaisonSociale(null);
     getClient().setEmail(null);
     getClient().setTel(null);
     
     
    }

  5. #5
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut
    mais le problème c'est qu'il prend la zone a modifié et celle d'ajout comme une seule zone : lorsque je client.raisonSocial dans le html:text ?

  6. #6
    Membre confirmé
    Inscrit en
    Juillet 2002
    Messages
    225
    Détails du profil
    Informations forums :
    Inscription : Juillet 2002
    Messages : 225
    Par défaut
    Citation Envoyé par newmar Voir le message
    mais le problème c'est qu'il prend la zone a modifié et celle d'ajout comme une seule zone : lorsque je client.raisonSocial dans le html:text ?
    désolé ..je comprends pas

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

Discussions similaires

  1. Problème initialisation formulaire et formset
    Par polo42 dans le forum Django
    Réponses: 0
    Dernier message: 08/05/2013, 14h30
  2. Problème initialisation formulaire
    Par JoloKossovar dans le forum Struts 1
    Réponses: 2
    Dernier message: 12/05/2008, 11h19
  3. [Struts] Problème de formulaire(s) ...
    Par djoukit dans le forum Struts 1
    Réponses: 8
    Dernier message: 10/03/2004, 23h48
  4. [Plugin] Problème initialisation plugin ResourcesPlugin
    Par Michael I. dans le forum Eclipse Platform
    Réponses: 1
    Dernier message: 06/02/2004, 13h27
  5. Réponses: 12
    Dernier message: 24/09/2003, 15h26

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