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 2 Java Discussion :

Problème Struts 2


Sujet :

Struts 2 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 33
    Par défaut Problème Struts 2
    Bonsoir,

    Je souhaite afficher une liste de serveurs contenu dans une arraylist.
    Pour cela j'utilise une variable de session ainsi qu'une Jsp mais cela ne fonctionne pas !!!
    Voici mon 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
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    public class ListeCommandeAction extends ActionSupport implements SessionAware {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
    	ModelCafe c;	
     
     
    	Map<String, Object> session;
     
    	public String execute() throws Exception{
     
     
    		//assert((ModelCafe)getSession().get("cafe")!=null&&getSession().get("cafe").getClass()==ModelCafe.class);
     
    		c=(ModelCafe)getSession().get("cafe");
     
     
    		if (c==null) {					
    			c = new ModelCafe();
    			getSession().put("cafe", c);
     
     
    		}			
    		return SUCCESS;
     
    	}

    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
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!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>
     
    	<h4>Liste des boissons</h4>
     
    	<table>
     
     
    		<s:iterator value="#session.cafe">
    			<tr>
    				<td><s:property value="numeroServeur" /></td>
     
    			</tr>
    		</s:iterator>
    	</table>
    </body>
    </html>
    Merci d'avance pour votre aide !!!

  2. #2
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Mai 2006
    Messages
    226
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mai 2006
    Messages : 226
    Par défaut
    Salut,

    il nous faudrait des infos sur "c" et sur "ModelCafe", c'est une liste ? il y a des valeurs dedans ?

  3. #3
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 33
    Par défaut
    Je vous remercie avant tout d'avoir pris le temps de lire mon problème
    ModelCafe est mon modèle, il contient ma liste de boissons que je souhaite ajouter dans ma commande.

    La classe ModelCafe:

    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
     
     
    package modele;
     
    import java.util.AbstractCollection;
    import java.util.ArrayList;
     
    import java.util.HashMap;
    import java.util.Iterator;
     
     
    import java.util.Map;
     
     
    public class ModelCafe extends AbstractCollection<Commande>{
     
     
    	public ArrayList<String>listesBoissons;
    	//public ArrayList<Commande>listCommande;
    	int numeroServeur;
     
    	private Map<Integer,Commande>listCommande;
    	private static int LAST_ID=0;
     
     
    	public ModelCafe() {
     
    		listesBoissons = new ArrayList<String>();
    		listCommande =  new HashMap<Integer,Commande>();
     
    		listesBoissons.add("bobo");
    		listesBoissons.add("baba");
     
     
    		ajouterCommandeS(listesBoissons);
    		ajouterCommandeS(listesBoissons);
    		ajouterCommandeS(listesBoissons);
     
     
    		System.out.println("Commande ajoutée");
     
    		for(Iterator<Integer> i = listCommande.keySet().iterator(); i.hasNext();){
    			Integer key = i.next();
     
    			System.out.println("valeur" + " "+ key + " " + listCommande.get(key).getListesBoissons());
    		}
     
    	}
     
    	public void ajouterCommande(ArrayList<String>listesBoissons,int numeroServeur){
    		LAST_ID++;
    		listCommande.put(LAST_ID,new Commande(listesBoissons,LAST_ID));
     
    		for(Iterator<Integer> i = listCommande.keySet().iterator(); i.hasNext();){
    			Integer key = i.next();
     
    			System.out.println("valeur" + " "+ key + " " + listCommande.get(key).getListesBoissons());
    		}
    	}
     
    	public ArrayList<String> getListesBoissons() {
    		return listesBoissons;
    	}
     
    	public void setListesBoissons(ArrayList<String> listesBoissons) {
    		this.listesBoissons = listesBoissons;
    	}
     
     
    	public void ajouterCommandeS(ArrayList<String>listesBoissons){
    		LAST_ID++;
    		listCommande.put(LAST_ID,new Commande(listesBoissons));
    	}
     
    	public int getNumeroServeur() {
    		return numeroServeur;
    	}
     
    	public void setNumeroServeur(int numeroServeur) {
    		this.numeroServeur = numeroServeur;
    	}
     
    	public Commande getCommande(int i){
    		return listCommande.get(i);
    	}
     
    	public int getSizelistCommande(){		
    		return listCommande.size();
    	}
     
    /*
    	public int size() {
    		return listesBoissons.size();
    	}
    	*/
     
     
    	public int getSizelisteBoisson(){
     
    		int N = this.getSizelistCommande();
     
    		int min =getCommande(0).getListesBoissons().size();
    		int max = getCommande(0).getListesBoissons().size();
     
    		int i = 0; 
    		//		System.out.println(j);
    		while (i<N){
    			i=i+1;
    			if(i==N) return max;
    			if(getCommande(i).getListesBoissons().size()>max)
    				max = getCommande(i).getListesBoissons().size();
    			if(getCommande(i).getListesBoissons().size()<min)
    				min = getCommande(i).getListesBoissons().size();
     
    		}
     
    		return max;
    	}
     
    	@Override
    	public Iterator<Commande> iterator() {
    		// TODO Auto-generated method stub
    		return listCommande.values().iterator();
    	}
     
    	@Override
    	public int size() {
    		// TODO Auto-generated method stub
    		return listCommande.size();
    	}
     
     
    }
    le 'c', je l'ai modifié depuis il devenu mc : c'est la variable de session.

    La classe AfficheBoissons:

    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
     
    package controleur.action;
     
    import java.util.ArrayList;
    import java.util.Map;
     
    import org.apache.struts2.interceptor.SessionAware;
     
    import modele.Commande;
    import modele.ModelCafe;
     
    import com.opensymphony.xwork2.ActionSupport;
     
    public class AfficheBoissons extends ActionSupport implements SessionAware{
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
     
    	private  ArrayList<String> boissonslistesLeft= new ArrayList<String>();
    	private ArrayList<String> listeTables = new ArrayList<String>();
     
    	//private  ArrayList<String> listesBoissons = new ArrayList<String>();
     
     
    	Map<String, Object> session;
    	Commande cmd;
    	ModelCafe mc;
     
    	public AfficheBoissons(){
     
    		super();
    		cmd = new Commande();
    		mc= new ModelCafe();
     
    		boissonslistesLeft.add("Eau");
    		boissonslistesLeft.add("Jus d'orange");
    		boissonslistesLeft.add("Coca");
    		boissonslistesLeft.add("Cafe");
    		listeTables.add("1");
    		listeTables.add("2");
    		listeTables.add("3");
     
    		//listesBoissons.add("Fraise");
    		//listesBoissons.add("Chocolat");
     
    	}
     
    	public ArrayList<String> getListeTables() {
    		return listeTables;
    	}
     
    	public void setListeTables(ArrayList<String> listeTables) {
    		this.listeTables = listeTables;
    	}
     
    	public Map<String, Object> getSession() {
    		return session;
    	}
     
    	public void setSession(Map<String, Object> session) {
    		this.session = session;
    	}
     
    	public ArrayList<String> getBoissonslistesLeft() {
    		return boissonslistesLeft;
    	}
     
    	public void setBoissonslistesLeft(ArrayList<String> boissonslistesLeft) {
    		this.boissonslistesLeft = boissonslistesLeft;
    	}
     
     
     
    	public ArrayList<String> getListesBoissons() {
    		return cmd.getListesBoissons();
    	}
     
    	public void setListesBoissons(ArrayList<String> listesBoissons) {
    		cmd.setListesBoissons(listesBoissons);
    	}
     
    	/*
    	public String execute() throws Exception {
     
     
    		ModelCafe mc=(ModelCafe)getSession().get("modelCafe");
     
    		System.out.println(getListesBoissons());
    		cmd.setListesBoissons(getListesBoissons());
    		System.out.println(cmd.getListesBoissons());
     
    		System.out.println("ici1");
    		if(mc!=null){
    			System.out.println("ici2");
    			System.out.println(getListesBoissons());
    			System.out.println("ici3");
    			mc.ajouterCommandeS(getListesBoissons());
    			System.out.println("ici4");
    			return SUCCESS;
    		}
    		else{
     
    			return ERROR;
    		}
    	}
    	 */
    	public String execute() throws Exception {
    		ModelCafe mc=(ModelCafe)getSession().get("cafe");
    		//mc=(ModelCafe) session.get("cafe");
     
    		//mc= new ModelCafe();
    		session.put("cafe", mc);
     
    		System.out.println("val de mc"+ " " + mc);
     
    		System.out.println(getListesBoissons());
    		mc.ajouterCommandeS(getListesBoissons());
    		System.out.println("val de mc ap"+ " " + mc);
    		return SUCCESS;
    	}
     
     
    	public String display() {
    		return NONE;
    	}
     
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Mai 2006
    Messages
    226
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mai 2006
    Messages : 226
    Par défaut
    Salut,

    en fait on est mal parti ^^. Ce qui faudrait en premier temps c'est que tu expliques précisément ce que tu veux faire et ce qui ne marche pas, dans ton premier post tu parles d'afficher une liste de serveurs mais d'après ce que je vois nulle part tu ne références le numéro du serveur...

    quand tu arrives dans la méthode execute, est-ce que "mc" est déjà sensé être dans la session ??

    et si tu pouvais montrer la classe Commande et le struts.xml. ça sera utile si je veux essayer de reproduire ton exemple.

  5. #5
    Membre averti
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2011
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 33
    Par défaut
    Bonjour,

    je voulais insérer au départ des serveurs ensuite j'ai opté pour la liste de boissons.

    Pour être plus précise:

    On nous demande de faire un projet dans lequel il faut gérer une liste de commandes(dans mon cas, il s'agit d'une hashMap).
    Dans la commande, il y a une liste de boissons, une liste de table et une liste de serveur.
    Je souhaite ajouter ma liste de boissons dans ma commande.

    Dans le code que je vais vous envoyer, il fonctionne mais une fois sur deux.
    Le problème qui se posait était que l'objet mc n'était pas dans la session.
    Et il est une fois sur deux également.
    Et c'est ça que je ne comprends pas ???
    L'erreur:

    Struts Problem Report
    Struts has detected an unhandled exception:

    Messages:
    File: controleur/action/AfficheBoissons.java
    Line number: 157

    java.lang.NullPointerException
    controleur.action.AfficheBoissons.execute(AfficheBoissons.java:157)



    Et quand j'affiche la valeur de mc, il est null.

    Entre temps, j'ai beaucoup de changement !!!

    La commande:

    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
     
    package model;
     
    import java.util.ArrayList;
    import java.io.*;
     
    public class Commande implements Serializable{
     
    	private static final long serialVersionUID = -8493897757955097072L;
     
    	public enum Etat{Attente,Preparee,Servie}; //l'etat de la commande
    	Etat e;
    	int numeroCommande; //le numero unique d'une commande
    	ArrayList<String>listesBoissons; //le numero du serveur qui a prit la commande
    	int numeroServeur;
    	int table; //represente la table servie
    	static int LASTID=0;
     
     
    public Commande (ArrayList<String> listesBoissons, int numeroServeur, int table){
    	if(LASTID==0){
    		java.text.SimpleDateFormat f =new java.text.SimpleDateFormat("ddMMyy");
    		java.util.Date date=new java.util.Date();
    		int i=Integer.valueOf(f.format(date));
    		String s=String.valueOf(i);
    		s=i+"0001";
    		LASTID=Integer.parseInt(s);
    	}
    	numeroCommande=LASTID;
    	LASTID++;
    	this.numeroServeur=numeroServeur;
    	this.listesBoissons = listesBoissons;
    	this.numeroServeur = numeroServeur;
    	this.e= Etat.Attente;	
    	this.table=table;
    }
     
    public Commande(){
    	if(LASTID==0){
    		java.text.SimpleDateFormat f =new java.text.SimpleDateFormat("ddMMyy");
    		java.util.Date date=new java.util.Date();
    		int i=Integer.valueOf(f.format(date));
    		String s=String.valueOf(i);
    		s=i+"0001";
    		LASTID=Integer.parseInt(s);
    	}
    	e=Etat.Attente;
    	numeroCommande=LASTID; 
    	LASTID++;
    	listesBoissons=new ArrayList<String>();
    	numeroServeur=-1;
    	this.table=-1;
    }
     
    /* LES GETTERS ET LES SETTERS */
     
    public Etat getE() {
    	return e;
    }
     
     
    public void setE(Etat e) {
    	this.e = e;
    }
     
     
    public ArrayList<String> getListesBoissons() {
    	return listesBoissons;
    }
     
     
    public void setListesBoissons(ArrayList<String> listesBoissons) {
    	this.listesBoissons = listesBoissons;
    }
     
     
    public int getNumeroServeur() {
    	return numeroServeur;
    }
     
     
    public void setNumeroServeur(int numeroServeur) {
    	this.numeroServeur = numeroServeur;
    }
     
    public int getNumeroCommande(){
    	return numeroCommande;
    }
     
    public void setNumeroCommande(int numeroCommande) {
    	this.numeroCommande = numeroCommande;
    }
     
    public void setTable(int table){
    	this.table=table;
    }
     
    public int getTable(){
    	return table;
    }
     
    }
    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
     
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
     
    <struts>
    	<constant name="struts.custom.i18n.resources" value="package" />
    	<constant name="struts.enable.DynamicMethodInvocation" value="false" />
    	<constant name="struts.devMode" value="true" />
     
    	<package name="default" namespace="/" extends="struts-default">
     
    		<default-action-ref name="index" />
     
    		<action name="index">
    			<result type="redirect">
    				pages/index.jsp
    			</result>
    		</action>
     
    		<action name="liste_boissons" class="controleur.action.ListeCommandeAction"
    			method="execute">
    			<result name="success">/pages/liste_boissons.jsp</result>
    		</action>
     
    		<action name="ajout_commande_boissons" class="controleur.action.AfficheBoissons"
    			method="display">
    			<result name="none">/pages/ajout_commande_boissons.jsp</result>
    		</action>
     
    		<action name="ajout" class="controleur.action.AfficheBoissons">
    			<result name="success">/pages/ajout_commande_boissons.jsp</result>
    			<result name="success">/pages/result_boissons.jsp</result>
    			<result name="input">/pages/ajout_commande_boissons.jsp</result>
    		</action>
     
    		<action name="effacerCMD" class="controleur.action.ListeCommandeAction"
    			method="effacerCMD">
    			<result name="success">/pages/liste_boissons.jsp</result>
    		</action>
     
    		 <action name="barman" class="controleur.action.InterfaceBarmanAction" method="execute">
                <result name="success">barman.jsp</result>
            	<result name="error">error.jsp</result>
            </action>
     
            <action name="detail" class="controleur.action.DetailsCommandeAction" method="execute">
            	<result name="success">/pages/affiche_commande.jsp</result>
            </action>
    	</package>
     
     
     
    	<!-- Add packages here -->
     
    </struts>
    La AfficheBoissons.java

    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
     
     
    package controleur.action;
     
    import java.util.ArrayList;
    import java.util.Map;
     
    import model.Commande;
    import model.ModelCafe;
     
    import org.apache.struts2.interceptor.SessionAware;
    import com.opensymphony.xwork2.ActionSupport;
     
    public class AfficheBoissons extends ActionSupport implements SessionAware{
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
     
    	private  ArrayList<String> boissonslistesLeft= new ArrayList<String>();
    	private ArrayList<Integer> listeTables = new ArrayList<Integer>();
    	private ArrayList<Integer>listServeur = new ArrayList<Integer>();
     
    	int serveur;
    	int table;
     
     
    	//private  ArrayList<String> listesBoissons = new ArrayList<String>();
     
     
    	Map<String, Object> session;
    	Commande cmd;
    	ModelCafe mc;
     
    	public AfficheBoissons(){
     
    		super();
    		cmd = new Commande();
    		mc= new ModelCafe();
     
    		boissonslistesLeft.add("Eau");
    		boissonslistesLeft.add("Jus d'orange");
    		boissonslistesLeft.add("Coca");
    		boissonslistesLeft.add("Cafe");
    		listeTables.add(1);
    		listeTables.add(2);
    		listeTables.add(3);
    		listServeur.add(1);
    		listServeur.add(2);	
     
    		//listesBoissons.add("Fraise");
    		//listesBoissons.add("Chocolat");
     
    	}
     
     
     
    	public int getServeur() {
    		return serveur;
    	}
     
    	public void setServeur(int serveur) {
    		this.serveur = serveur;
    	}
     
     
    	public int getTable() {
    		return table;
    	}
     
     
    	public void setTable(int table) {
    		this.table = table;
    	}
     
     
    	public ArrayList<Integer> getListServeur() {
    		return listServeur;
    	}
     
    	public void setListServeur(ArrayList<Integer>listServeur) {
    		this.listServeur = listServeur;
    	}
     
    	public ArrayList<Integer> getListeTables() {
    		return listeTables;
    	}
     
    	public void setListeTables(ArrayList<Integer> listeTables) {
    		this.listeTables = listeTables;
    	}
     
    	public Map<String, Object> getSession() {
    		return session;
    	}
     
    	public void setSession(Map<String, Object> session) {
    		this.session = session;
    	}
     
    	public ArrayList<String> getBoissonslistesLeft() {
    		return boissonslistesLeft;
    	}
     
    	public void setBoissonslistesLeft(ArrayList<String> boissonslistesLeft) {
    		this.boissonslistesLeft = boissonslistesLeft;
    	}
     
     
     
    	public ArrayList<String> getListesBoissons() {
    		return cmd.getListesBoissons();
    	}
     
    	public void setListesBoissons(ArrayList<String> listesBoissons) {
    		cmd.setListesBoissons(listesBoissons);
    	}
     
    	/*
    	public String execute() throws Exception {
     
     
    		ModelCafe mc=(ModelCafe)getSession().get("modelCafe");
     
    		System.out.println(getListesBoissons());
    		cmd.setListesBoissons(getListesBoissons());
    		System.out.println(cmd.getListesBoissons());
     
    		System.out.println("ici1");
    		if(mc!=null){
    			System.out.println("ici2");
    			System.out.println(getListesBoissons());
    			System.out.println("ici3");
    			mc.ajouterCommandeS(getListesBoissons());
    			System.out.println("ici4");
    			return SUCCESS;
    		}
    		else{
     
    			return ERROR;
    		}
    	}
    	 */
     
    	public String execute() throws Exception {
    		ModelCafe mc=(ModelCafe)getSession().get("cafe");
    		//mc=(ModelCafe) session.get("cafe");
     
    		//mc= new ModelCafe();
    		session.put("cafe", mc);
     
    		System.out.println("val de mc"+ " " + mc);
     
    		System.out.println(getListesBoissons());
     
     
    		mc.ajouterCommande(getListesBoissons(),getServeur(),getTable());
     
    		System.out.println("val de mc ap"+ " " + mc);
    		return SUCCESS;
    	}
     
     
    	public String display() {
    		return NONE;
    	}
     
    }
    ajout_commande_boissons.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
     
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="s" uri="/struts-tags"%>
    <!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>
     
    	<h1>LES BOISSONS</h1>
     
    	<s:form action="ajout" key="#session.cafe">
     
    		<s:optiontransferselect label="Boissons" name="leftBoissons"
    			leftTitle="Left Boissons Title" rightTitle="Right boissons Title"
    			list="BoissonslistesLeft" multiple="true" headerKey="-1"
    			headerValue="--- Boissons à choisir -----"
    			doubleList="listesBoissons" doubleName="listesBoissons"
    			doubleHeaderKey="-1" doubleHeaderValue="Boissons choisies" key="listesBoissons" />
     
    			<s:combobox label="La table" 
    		headerKey="-1" headerValue="--- Select ---"
    		list="listeTables" 
    		name="table" />
     
    		<s:select label="Le serveur" 
    		headerKey="-1" headerValue="--- Select ---"
    		list="listServeur" 
    		name="serveur" />
     
    		<s:submit key ="commander"/>
     
    	</s:form>
     
    </body>
    </html>
    J'espère que je suis claire, merci encore du temps que vous m'accordez !!!

  6. #6
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Mai 2006
    Messages
    226
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mai 2006
    Messages : 226
    Par défaut
    Yop,

    si j'ai tout compris, c'est dans la méthode execute que ça plante, parce que tu récupère "cafe" dans la session, mais tu l'as jamais mis dedans avant, donc ça te retournes un objet null et donc quand tu fais "ajouterCommande" t'as un null pointer...

    il faudrait que tu essayes un truc comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    ModelCafe mc=(ModelCafe)getSession().get("cafe");
    if( mc == null) {
    mc = new ModelCafe();
    }

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

Discussions similaires

  1. problème struts jsp
    Par saritta27 dans le forum Struts 1
    Réponses: 14
    Dernier message: 09/06/2009, 03h10
  2. Problème Struts 2 et WebSphere
    Par kelidric dans le forum Struts 2
    Réponses: 7
    Dernier message: 29/04/2009, 14h14
  3. Réponses: 2
    Dernier message: 30/05/2007, 20h25
  4. problème struts JSP
    Par yaya0057 dans le forum Struts 1
    Réponses: 2
    Dernier message: 21/05/2007, 18h19
  5. [Struts] [Tomcat] problème struts-config
    Par danyboy85 dans le forum Tomcat et TomEE
    Réponses: 7
    Dernier message: 10/02/2006, 14h50

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