Bonjour, j'ai un petit souci au niveau de la cast.
je ramène des données d'une requête

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
private java.util.List<gestcom.components.VopD> VopDataList;
private javax.persistence.Query VopDataQuery;
 
VopDataQuery = java.beans.Beans.isDesignTime() ? null : gestcomPUEntityManager.createQuery("SELECT o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens,sum(e.montant) from Operation o ,Ecriture e where o.code = e.operation and e.sens= 'C' group by o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens");
 
        VopDataList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : structureQuery.getResultList();
Pour récupérer ses données de la requête j'ai crée une classe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
public class VopD {
       public Structure  structure;
       public Nature  nature;
       public String  libelle;
       public String  objet;
       public Date    date_deb;
       public Date    date_fin;
       public Long    montant;
       public Long    paye;
    }
pour gérer l'affichage la classe
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
 
public class VopData {
  public static ImageIcon ICON_UP = new ImageIcon("ArrUp.gif");
  public static ImageIcon ICON_DOWN = new ImageIcon("ArrDown.gif");
  public static ImageIcon ICON_BLANK = new ImageIcon("blank.gif");
 
  private IconData  structure;
  private Integer   nature;
  private String    libelle;
  private String    objet;
  private Date      date_deb;
  private Date      date_fin;
  private SmartLong montant;
  private SmartLong paye;
  private float     progress;
 
  public VopData(Structure structure,
                 Nature nature,
                 String libelle,
                 String objet,
                 Date date_deb,
                 Date date_fin,
                 Long montant,
                 Long paye){
	 this.structure = new IconData(getIcon(montant,paye), structure.getCode());
	 this.nature    = nature.getCode();
         this.libelle = libelle;
	 this.objet = objet;
         this.date_deb = date_deb;
	 this.date_fin = date_fin;
         this.montant = new SmartLong(montant);
	 this.nature = nature.getCode();
         this.paye = new SmartLong(paye);
	 this.progress = (float)((paye/montant) * 100);
  }
 
  public static ImageIcon getIcon(double change) {
    return (change>0 ? ICON_UP : (change<0 ? ICON_DOWN :
      ICON_BLANK));
  }
  public static ImageIcon getIcon(Long m1, Long m2) {
    return (m1>m2 ? ICON_UP : (m1<=m2 ? ICON_DOWN :
      ICON_BLANK));
  }
 
  public String getStructure() { return structure.toString(); }
  public Integer getNature() { return nature; }
  public String getLibelle() { return libelle; }
  public String getObjet() { return objet; }
  public Date getDatedeb() { return date_deb; }
  public Date getDatefin() { return date_fin; }
  public Long getMontant() { return montant.longValue(); }
  public Long getPaye() { return paye.longValue(); }
  public float getProgress() { return progress; }
  public String toString(){ return "[ pourcentage de réalisation : " + this.progress + "% ]";}
}
Dans ma classe model pour la correspondance des données je fais:
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
 
public VopModel(java.util.List<gestcom.components.VopD>dataList){
      setData(dataList);
  }
 
  public void setData(java.util.List<gestcom.components.VopD> dataList){
      m_frm = new SimpleDateFormat("MM/dd/yyyy");
      model.removeAllElements();
     //Object[] values = dataList.getSelectedValues();
     for (int i = 0; i<dataList.size(); i++) {
        //outputListModel.addElement(values[i]);
        model.addElement(new VopData(dataList.get(i).structure,
                                     dataList.get(i).nature,
                                     dataList.get(i).libelle,
                                     dataList.get(i).objet,
                                     dataList.get(i).date_deb,
                                     dataList.get(i).date_fin,
                                     dataList.get(i).montant,
                                     dataList.get(i).paye));
     }
     // the table model is interested in changes of the rows
     fireTableRowsInserted(model.size()-1, model.size()-1);
  }
A l'exécution j'ai l'erreur
[TopLink Info]: 2009.09.30 07:50:56.515--ServerSession(13419912)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))
[TopLink Info]: 2009.09.30 07:50:56.937--ServerSession(13419912)--file:/C:/workspace/Netbeans/Gestcom/build/classes/-gestcomPU login successful
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: gestcom.entities.Structure cannot be cast to gestcom.components.VopD
at gestcom.components.VopModel.setData(VopModel.java:90)
at gestcom.components.VopModel.<init>(VopModel.java:81)
at gestcom.view.F_CE_Operation.initComponents(F_CE_Operation.java:65)
at gestcom.view.F_CE_Operation.<init>(F_CE_Operation.java:25)
at gestcom.view.F_CE_Operation$1.run(F_CE_Operation.java:144)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 2 seconds)
qui pointe dans la classe model sur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
model.addElement(new VopData(dataList.get(i).structure,
                                     dataList.get(i).nature,
                                     dataList.get(i).libelle,
                                     dataList.get(i).objet,
                                     dataList.get(i).date_deb,
                                     dataList.get(i).date_fin,
                                     dataList.get(i).montant,
                                     dataList.get(i).paye));
je ne vois pas pourquoi alors je sollicite votre aide