String cannot be cast to Integer
Salut,
s'il vous plaît aide moi, ce code toujours il m'affiche cette erreur, je ne sais pas ou exactement le problème :(
Code:
1 2 3 4
|
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
.....listProduitsInList(GestionProduitImpl.java:111)
.....getNameproduit(DemandeBean.java:436) |
ligne 111: List<Object[]> rows = session.createQuery(hql).setParameterList("ids", li).list();
ligne 436: nameproduit = (Map<Integer, String>) dao1.listProduitsInList(l);
classe produit:
Code:
1 2 3 4 5 6 7 8 9 10
|
public class Produit implements java.io.Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "REFERENCE", nullable = false)
private int reference;
@Column(name = "DESIGNATION", nullable = false)
private String designation;
....
} |
Code:
1 2 3 4 5 6 7 8 9 10 11
|
public Map<Integer, String> listProduitsInList(List<Integer> li) {
Session session = HibernateUtil.getSessionFactory().openSession();
String hql = "select p.reference, p.designation from Produit p where p.reference in (:ids)";
List<Object[]> rows = session.createQuery(hql).setParameterList("ids", li).list();
Map<Integer, String> q = new HashMap<Integer, String>();
for (Object[] row : rows) {
q.put(Integer.parseInt(row[0].toString()), (String) row[1]);
}
return q;
} |
dans bean @ViewScoped
Code:
1 2 3 4 5 6 7 8 9 10
|
private List<Integer> l = new ArrayList<Integer>();
private Map<Integer, String> nameproduit;
public Map<Integer, String> getNameproduit() {
if (!l.isEmpty()) {
nameproduit = (Map<Integer, String>) dao1.listProduitsInList(l);
}
return nameproduit;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
<h:form>
<h:panelGrid>
<p:selectCheckboxMenu value="#{DemandeBean.l}">
<f:selectItems value="#{produitBean.itemProduitCond}" />
<p:commandButton value="test" update="display" ajax="false" />
</p:selectCheckboxMenu>
</h:panelGrid>
<p:outputPanel id="display">
<p:dataList value="#{DemandeBean.nameproduit.entrySet().toArray()}" var="prd" >
#{prd.key}
#{prd.value}
</p:dataList>
</p:outputPanel>
</h:form> |