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 avec la méthode validate


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 avec la méthode validate
    Bonjour, jusqu'à maintenant j'ai pu créer mon clientsForm, et mes pages Clients.jsp, ajoutClient.jsp, editClient.jsp, tout marche tres tres bien mais lorsque j'ai voulu controler les données saisie j'ai trouvé enormement de problème il me dit que :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    message No input attribute for mapping path /gestClient
     
    description Le serveur a rencontré une erreur interne (No input attribute for mapping path /gestClient) qui l'a empêché de satisfaire la requête.
    struts-config.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
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
              "http://struts.apache.org/dtds/struts-config_1_2.dtd">
     
    <struts-config>
     <form-beans>
     	<form-bean name="cfc" type="presentation.str.ClientsForm"/>
     </form-beans>
     <global-forwards>
      <forward name="VueClient" path="client.page"/>
      <forward name="addClient" path="ajoutclient.page"/>
      <forward name="editClient" path="editclient.page"/>
     </global-forwards>
     <action-mappings>
     
    	 <action 
    	 path="/gestClient" 
    	 name="cfc" 
    	 type="presentation.str.ClientsAction" 
    	 scope="session"
         validate="true">
         </action>  
     
     </action-mappings>
     
     <message-resources parameter="ApplicationResources"/>   
     <!-- Tiles Configuration -->
    <plug-in className="org.apache.struts.tiles.TilesPlugin">
      <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
    </plug-in>
     
    </struts-config>
    ClientsForm :
    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
    package presentation.str;
     
    import java.util.List;
    import java.util.Vector;
     
    import javax.servlet.http.HttpServletRequest;
     
    import ma.corporate.planning.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 ClientsForm extends ActionForm  {
     
    	private String motcle;
    	private List<Client> clients = new Vector<Client>();
    	private String action = "";
    	private int idClient;
    	private Client client = new Client();
    	private String raisonSocial;
    	private String adresse;
    	private String tel;
    	private String email;
    	private String ville;
    	private String pays;
     
     
    	public String getMotcle() {
    		return motcle;
    	}
    	public void setMotcle(String motcle) {
    		this.motcle = motcle;
    	}
    	public List<Client> getClients() {
    		return clients;
    	}
    	public void setClients(List<Client> clients) {
    		this.clients = clients;
    	}
    	public String getAction() {
    		return action;
    	}
    	public void setAction(String action) {
    		this.action = action;
    	}
    	public int getIdClient() {
    		return idClient;
    	}
    	public void setIdClient(int idClient) {
    		this.idClient = idClient;
    	}
    	public Client getClient() {
    		return client;
    	}
    	public void setClient(Client client) {
    		this.client = client;
    	}
     
    	public String getRaisonSocial() {
    		return raisonSocial;
    	}
    	public void setRaisonSocial(String raisonSocial) {
    		this.raisonSocial = raisonSocial;
    	}
    	public String getAdresse() {
    		return adresse;
    	}
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
    	public String getTel() {
    		return tel;
    	}
    	public void setTel(String tel) {
    		this.tel = tel;
    	}
    	public String getEmail() {
    		return email;
    	}
    	public void setEmail(String email) {
    		this.email = email;
    	}
    	public String getVille() {
    		return ville;
    	}
    	public void setVille(String ville) {
    		this.ville = ville;
    	}
    	public String getPays() {
    		return pays;
    	}
    	public void setPays(String pays) {
    		this.pays = pays;
    	}
     
    	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
    		ActionErrors errors = new ActionErrors();
     
    		if ((raisonSocial == null) || (raisonSocial.length() < 1))
    		errors.add("raisonSocial", new ActionError("error.raisonSocial.vide"));
    		if ((adresse == null) || (adresse.length() < 1))
    		errors.add("adresse", new ActionError("error.adresse.vide"));
    		if ((tel == null) ){
    		errors.add("tel", new ActionError("error.tel.vide"));
    		}
    		else {
    			if (!tel.matches("^\\s*\\d+\\s*$") || (tel.length() < 9)) {
    			errors.add("telinvalide", new ActionError("error.tel.invalide"));
    			}
    			}
    		if ((email == null) || (email.length() < 1)){
    			errors.add("email", new ActionError("error.email.vide"));
    		}
    		else {
    			if (!email.matches(".+@.+\\.[a-z]+")) {
    			errors.add("emailinvalide", new ActionError("error.email.invalide"));
    			}
    			}
    		if ((ville == null) || (ville.length() < 1)){
    			errors.add("ville", new ActionError("error.ville.vide"));	
    		}//(!ville.matches("[^0-9]*")) 
    		else {
    			if (!ville.matches("[^0-9]*")) {
    			errors.add("villeinvalide", new ActionError("error.ville.invalide"));
    			}
    			}
    		if ((pays == null) || (pays.length() < 1)){
    			errors.add("pays", new ActionError("error.pays.vide"));
    		}
    		else {
    			if (!pays.matches("[^0-9]*")) {
    			errors.add("paysinvalide", new ActionError("error.pays.invalide"));
    			}
    			}
    		return errors;
    	}
     
     
     
    }
    Clients.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
     
    <%@ 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"%>
    <%@ page import="ma.corporate.planning.metier.*"%>
     
    <html:form action="gestClient.do">
      <p>&nbsp;</p>
      <p>
    <span class="label">Client :</span>
    <html:text property="motcle" value=""></html:text>
             <html:submit value="Chercher" property="action" styleClass="search"></html:submit>
            <html:submit value="Ajouter" property="action" styleClass="add"></html:submit>
     </p>
     <br>
     <p>
     <table border="1" width="90%" bordercolor="294C9E" align="center">
      <tr  class="submit">
       <th>Raison Social</th><th>Adresse</th><th>Email</th><th>Tel</th><th>Ville</th><th colspan="2">&nbsp;</th>
      </tr>
      <%int nb=0; %>
      <logic:iterate id="cli" name="cfc" property="clients" type="Client">
      <tr
      <%if(nb==0){%> bgcolor="EAEEF1" <% nb=1;} else {%> bgcolor="A2BAD4" <% nb=0;} %>>
      		<td><bean:write name="cli" property="raisonSocial"/></td>
      		<td><bean:write name="cli" property="adresse"/></td>
      		<td><bean:write name="cli" property="email"/></td>
      		<td><bean:write name="cli" property="tel"/></td>
      		<td><bean:write name="cli" property="ville"/></td>
      		<td bgcolor="FFFFFF" align="center"><a href="gestClient.do?action=Editer&idClient=<%=cli.getIdClient() %>">
      		<img src="vues/images/modifier.png" border="0"></a></td>
      		<td bgcolor="FFFFFF" align="center"><a href="javascript:confirmation('gestClient.do?action=Supprimer&idClient=<%=cli.getIdClient() %>')">
      		<img src="vues/images/supprimer.jpg" border="0"></a></td>
     
      		</tr>
      		</logic:iterate>
      </table>
     
      </p>
      </html:form>
    je commence par clients.jsp, j'ajoute et je reviens a clients.jsp, lorsque je commente la méthode validate et je met :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	 <action 
    	 path="/gestClient" 
    	 name="cfc" 
    	 type="presentation.str.ClientsAction" 
    	 scope="session"
         />
    ca marche mais sans validation, please veuillez m'aider !

  2. #2
    Membre chevronné Avatar de JoloKossovar
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    532
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 532
    Par défaut
    Il faut que tu rajoute dans ton mapping de l'action /gestClient, un champ input qui va spécifier la jsp a l'origine de l'appel. Pour toi ce sera clients.jsp. Selon l'arborescence de tes fichiers ça donnera :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <action 
    	 path="/gestClient" 
             input="/WEB-INF/pages/clients.jsp"
    	 name="cfc" 
    	 type="presentation.str.ClientsAction" 
    	 scope="session"
         />
    Sinon, tu n'as pas besouin d'avoir dans ton projet les tld que tu importe au début des jsp. Mais nous verrons ca plus tard, une fois que tu aura résolu ton probleme ... Une chose à la fois

  3. #3
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut
    merci pour ta réponse, mais vraiment j'arrive pas a avancer, mais t'a pas mis de méthode validate, voila ce que j'ai fait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    	 <action 
    	 path="/gestClient"
    	 input="client.page"  
    	 name="cfc" 
    	 type="presentation.str.ClientsAction" 
    	 scope="session"
    	 validate="true">
    	 </action>
    et pour mon form : puisque avant je travaille qu'avec un client en totalité lorsque j'ai défini la methode validate j'ai mis ls attribut du client donc j'ai refais en faisant cela :
    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
    package presentation.str;
     
    import java.util.List;
    import java.util.Vector;
     
    import javax.servlet.http.HttpServletRequest;
     
    import ma.corporate.planning.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 ClientsForm extends ActionForm  {
     
    	private String motcle;
    	private List<Client> clients = new Vector<Client>();
    	private String action = "";
    	private int idClient;
    	private Client client = new Client();
    	private String raisonSocial;
    	private String adresse;
    	private String tel;
    	private String email;
    	private String ville;
    	private String pays;
     
     
    	public String getMotcle() {
    		return motcle;
    	}
    	public void setMotcle(String motcle) {
    		this.motcle = motcle;
    	}
    	public List<Client> getClients() {
    		return clients;
    	}
    	public void setClients(List<Client> clients) {
    		this.clients = clients;
    	}
    	public String getAction() {
    		return action;
    	}
    	public void setAction(String action) {
    		this.action = action;
    	}
    	public int getIdClient() {
    		return idClient;
    	}
    	public void setIdClient(int idClient) {
    		this.idClient = idClient;
    	}
    	public Client getClient() {
    		return client;
    	}
    	public void setClient(Client client) {
    		this.client = client;
    	}
     
    	public String getRaisonSocial() {
    		return raisonSocial;
    	}
    	public void setRaisonSocial(String raisonSocial) {
    		this.raisonSocial = raisonSocial;
    	}
    	public String getAdresse() {
    		return adresse;
    	}
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
    	public String getTel() {
    		return tel;
    	}
    	public void setTel(String tel) {
    		this.tel = tel;
    	}
    	public String getEmail() {
    		return email;
    	}
    	public void setEmail(String email) {
    		this.email = email;
    	}
    	public String getVille() {
    		return ville;
    	}
    	public void setVille(String ville) {
    		this.ville = ville;
    	}
    	public String getPays() {
    		return pays;
    	}
    	public void setPays(String pays) {
    		this.pays = pays;
    	}
     
    	public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
    		ActionErrors errors = new ActionErrors();
     
    		if ((getClient().getRaisonSocial() == null) || (getClient().getRaisonSocial().length() < 1))
    		errors.add("raisonSocial", new ActionError("error.raisonSocial.vide"));
     
    		return errors;
    	}
     
     
     
    }
    en conclusion, j'arrive a avoir ma bannière, ma pages mais rien ne foonctionne ?

  4. #4
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut
    Pas de solution a mon problème sachant que le input va etre varié si j'joute bien sur je vais revenir sur la page d'ajout s'il y une erreur sinon si je suis sur la partie modification je reviens a la page modif s'il y a des erreurs ?

  5. #5
    Membre chevronné Avatar de JoloKossovar
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    532
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2007
    Messages : 532
    Par défaut
    L’attribut ‘input’ permet de spécifier la page retournée en cas d’erreur.

  6. #6
    Membre éclairé
    Inscrit en
    Septembre 2007
    Messages
    372
    Détails du profil
    Informations forums :
    Inscription : Septembre 2007
    Messages : 372
    Par défaut
    il y a pas de solution je laisse la liberté au utilisateur pour entrer ce qu'il veut

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

Discussions similaires

  1. [Runtime] Problème avec la méthode 'exec'
    Par regisba dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 25/08/2006, 13h36
  2. Problème avec la méthode request.form()
    Par sam.fet dans le forum ASP
    Réponses: 2
    Dernier message: 11/08/2006, 17h11
  3. [POO] Problème avec setInterval/méthodes d'écriture
    Par Lpu8er dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 18/07/2006, 15h37
  4. problème avec la méthode getElementById() dans Firefox
    Par matrouba dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 19/12/2005, 08h55
  5. Problème avec la méthode pack()
    Par tomca dans le forum Langage
    Réponses: 5
    Dernier message: 15/09/2005, 10h58

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