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 :

objet dans le property de html:text


Sujet :

Struts 1 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 92
    Par défaut objet dans le property de html:text
    Bonjour,

    Dans mon form j'ai un objet nommé "client". Cette objet contient mes informations. Je souhaite travailler directement avec cet objet à parti de ma jsp.

    Pour cela j'ai écrit ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    <html:form action="/ficheClient.do">
    	<table><tr>
    		<!-- Nom -->
    		<td>
    			<bean:message key="ficheClient.nom" bundle="client"/>
    			<html:text property="client.nom_client"></html:text>
    		</td>
    	</tr></table>
    </html:form>
    Et j'ai cette exception:
    avax.servlet.ServletException: javax.servlet.jsp.JspException: Invalid argument looking up property: "client.nom_client" of bean: "org.apache.struts.taglib.html.BEAN"
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
    org.apache.jsp.vues.client.ficheClient_jsp._jspService(ficheClient_jsp.java:360)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
    org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
    org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    Struts ne permet pas ceci? si oui comment?

    Merci

  2. #2
    Expert confirmé

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Par défaut
    As-tu défini cet objet de type Client comme ceci dans l'ActionForm :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private Client client=new Client() ;
    Et sinon, nom_client est-elle bien une propriété de la classe Client ?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 92
    Par défaut
    oui,

    Mon action initialise mon client. Et la propriété est bien dans mon bean.

    C'est pour cela que je me demande si il est possible de faire ceci?

  4. #4
    Expert confirmé

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Par défaut
    Citation Envoyé par demanghonj Voir le message
    Mon action initialise mon client.
    Peux-tu montrer comment ?

    Citation Envoyé par demanghonj Voir le message
    C'est pour cela que je me demande si il est possible de faire ceci?
    oui, c'est possible.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 92
    Par défaut
    Voici la method de mon action:

    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
     
    /**
             * Ouvre la fiche client en mode ajout
             * @param actionMapping mapping
             * @param form formulaire
             * @param request requete http
             * @param response reponse http
             * @return
             */
    	public ActionForward nouveau(ActionMapping actionMapping, ActionForm form, 
    									HttpServletRequest request, HttpServletResponse response){
    		logger.debug("nouveau - IN");
    		try{
    			bean = (FicheClientForm)form;
    			bean.setClient(new Client());
    		}
    		catch (Exception e) {
    			logger.error("Impossible d'ouvrir la fiche client en mode ajout",e);
    			ActionErrors erreurs = new ActionErrors();
    			erreurs.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("ficheClient.erreur.nouveauClient"));
    			saveErrors(request, erreurs);
    		}
    		logger.debug("nouveau - OUT");
    		return actionMapping.findForward(ActionConstantes.SUCCESS);
    	}
    et voici le contenu de mon objet client

    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
    211
    212
    213
    214
    215
    216
     
    package application.entity;
     
    /**
     * Réprésentation d'un client
     * Image de la table Clients de la base de données
     * @author jdemanghon
     *
     */
    public class Client {
     
    	private static final long serialVersionUID = -7648276691012147478L;
     
    	/**
             * Images des champs en base
             */
    	private int id_client;//identifiant du client
    	private Integer id_utilisateur;//identifiant de l'utilisateur
    	private Integer id_groupe;//identifiant du groupe
    	private String nom_client;//nom du client
    	private String adresse1_client;//addresse 1 du client
    	private String adresse2_client;//adresse 2 du client
    	private String cp_client; //code postal du client
    	private String ville_client;//ville du client
    	private String tel_client;//téléphone du client
    	private String fax_client;//fax du client
    	private String activite_client;//activité du client
    	private String note_client;//note du client
    	private String secteurGeo;//secteur géographique
    	private boolean estSurListeRouge_client;//1 si il est sur la liste rouge sinon 0
    	private Integer categorie;//categorie du client
     
    	/**
             * Attributs d'informations supplémentaire
             */
    	private String nom_groupe;//nommm du groupe
    	private Long nombre_devis_en_cours;//nombre de devis en cours
    	private String nom_contact_principale;//nom du contact principale du client
    	private String prenom_contact_principale;//nom du contact principale du client
    	private String tel_contact_principale;//téléphone du contact principal du client
    	private boolean checked;//indique si le client à été coché depuis la liste des clients
     
    	public Client(){
     
    	}
     
    	public int getId_client() {
    		return id_client;
    	}
     
    	public void setId_client(int idClient) {
    		id_client = idClient;
    	}
     
    	public Integer getId_groupe() {
    		return id_groupe;
    	}
     
    	public void setId_groupe(Integer idGroupe) {
    		id_groupe = idGroupe;
    	}
     
    	public String getNom_client() {
    		return nom_client;
    	}
     
    	public void setNom_client(String nomClient) {
    		nom_client = nomClient;
    	}
     
    	public String getAdresse1_client() {
    		return adresse1_client;
    	}
     
    	public void setAdresse1_client(String adresse1Client) {
    		adresse1_client = adresse1Client;
    	}
     
    	public String getAdresse2_client() {
    		return adresse2_client;
    	}
     
    	public void setAdresse2_client(String adresse2Client) {
    		adresse2_client = adresse2Client;
    	}
     
    	public String getCp_client() {
    		return cp_client;
    	}
     
    	public void setCp_client(String cpClient) {
    		cp_client = cpClient;
    	}
     
    	public String getVille_client() {
    		return ville_client;
    	}
     
    	public void setVille_client(String villeClient) {
    		ville_client = villeClient;
    	}
     
    	public String getTel_client() {
    		return tel_client;
    	}
     
    	public void setTel_client(String telClient) {
    		tel_client = telClient;
    	}
     
    	public String getFax_client() {
    		return fax_client;
    	}
     
    	public void setFax_client(String faxClient) {
    		fax_client = faxClient;
    	}
     
    	public String getActivite_client() {
    		return activite_client;
    	}
     
    	public void setActivite_client(String activiteClient) {
    		activite_client = activiteClient;
    	}
     
    	public String getNote_client() {
    		return note_client;
    	}
     
    	public void setNote_client(String noteClient) {
    		note_client = noteClient;
    	}
     
    	public String getSecteurGeo() {
    		return secteurGeo;
    	}
     
    	public void setSecteurGeo(String secteurGeo) {
    		this.secteurGeo = secteurGeo;
    	}
     
    	public boolean getEstSurListeRouge_client() {
    		return estSurListeRouge_client;
    	}
     
    	public void setEstSurListeRouge_client(Boolean l_estSurListeRougeClient) {
    		if(l_estSurListeRougeClient == null)
    			l_estSurListeRougeClient = false;
    		estSurListeRouge_client = l_estSurListeRougeClient;
    	}
     
    	public Integer getCategorie() {
    		return categorie;
    	}
     
    	public void setCategorie(Integer categorie) {
    		this.categorie = categorie;
    	}
     
    	public Integer getId_utilisateur() {
    		return id_utilisateur;
    	}
     
    	public void setId_utilisateur(Integer idUtilisateur) {
    		id_utilisateur = idUtilisateur;
    	}
     
    	public String getNom_groupe() {
    		return nom_groupe;
    	}
     
    	public void setNom_groupe(String nomGroupe) {
    		nom_groupe = nomGroupe;
    	}
     
    	public Long getNombre_devis_en_cours() {
    		return nombre_devis_en_cours;
    	}
     
    	public void setNombre_devis_en_cours(Long nombreDevisEnCours) {
    		nombre_devis_en_cours = nombreDevisEnCours;
    	}
     
    	public String getNom_contact_principale() {
    		return nom_contact_principale;
    	}
     
    	public void setNom_contact_principale(String nomContactPrincipale) {
    		nom_contact_principale = nomContactPrincipale;
    	}
     
    	public String getTel_contact_principale() {
    		return tel_contact_principale;
    	}
     
    	public void setTel_contact_principale(String telContactPrincipale) {
    		tel_contact_principale = telContactPrincipale;
    	}
     
    	public String getPrenom_contact_principale() {
    		return prenom_contact_principale;
    	}
     
    	public void setPrenom_contact_principale(String prenomContactPrincipale) {
    		prenom_contact_principale = prenomContactPrincipale;
    	}
     
    	public boolean isChecked() {
    		return checked;
    	}
     
    	public void setChecked(boolean checked) {
    		this.checked = checked;
    	}
    }
    et voici mon form

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    public class FicheClientForm extends ActionForm {
     
    	private static final long serialVersionUID = -7648276691012147478L;
    	private Client client;
     
     
    	public Client getClient() {
    		return client;
    	}
    	public void setClient(Client client) {
    		this.client = client;
    	}
    }

  6. #6
    Expert confirmé

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Par défaut
    Le scope du form-bean est-il égal à request ou session dans le mapping de l'Action ?

    S'il est égal à request, il faut absolument définir l'objet client comme ceci dans l'ActionForm :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private Client client=new Client() ;
    Si tu le définis simplement comme ceci :
    quand tu vas soumettre le formulaire, une nouvelle requête va être créée et donc, une nouvelle instance de l'ActionForm aussi, et donc l'objet client de l'ActionForm FicheClientForm sera égal à null puisque tu ne l'instancies nulle part dans l'ActionForm.

    Sinon, comme tu sembles utiliser une DispatchAction ou une LookupDispatchAction, il vaudrait mieux mettre le scope du form-bean à session afin de garder les valeurs des propriétés de l'ActionForm après chaque Action effectuée sur le formulaire.

Discussions similaires

  1. Réponses: 2
    Dernier message: 27/10/2008, 13h50
  2. Réponses: 1
    Dernier message: 20/08/2008, 13h49
  3. Réponses: 10
    Dernier message: 19/03/2008, 11h06
  4. [POO] Inclure php objet dans html
    Par Matgic95 dans le forum Langage
    Réponses: 2
    Dernier message: 29/12/2006, 09h51
  5. recherche en texte libre dans des champs codés html
    Par boteha dans le forum Requêtes
    Réponses: 9
    Dernier message: 04/12/2005, 22h26

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