-1
我想從我的數據的基礎上填寫的selectOneMenu用於,但始終列表爲空 這是我的代碼:如何填寫selectOneMenu用於JSF
public ArrayList<String> FindListKpi(Integer userid)
{
ArrayList<String> usrpr=new ArrayList<String>();
try{
EntityTransaction entr=em.getTransaction();
entr.begin();
javax.persistence.Query multipleSelect= em.createQuery("select k.kpiName FROM ProfilUser p, Kpi k, AssociationKpiProfil a WHERE p= a.profilUser and a.kpi=k and p.profilUserId= :w");
multipleSelect.setParameter("w", userid);
/* to tranform list to an arraylist*/
List usrpro = new LinkedList();
usrpro= multipleSelect.getResultList();
usrpr = new ArrayList(usrpro);
entr.commit();
System.out.println("listttttttttttttttttttttttt"+usrpr.toString());
return usrpr;
}
catch (Exception e)
{
System.out.println(e.getMessage());
System.out.println("error");
}
finally {
em.close();
}
return usrpr;
}
我的功能,填補選擇框:
public List<SelectItem> getMyListKPIs() {
FindKpi fkpi =new FindKpi();
if (MyListKPI == null) {
MyListKPI = new ArrayList<SelectItem>();
for (String val : fkpi.FindListKpi(iduser)) {
MyListKPI.add(new SelectItem(val));
}
}
return MyListKPI;
}
結果: listttttttttttttttttttttttt []
我測試了我的方法「FindListKpi」,它工作正常:
public static void main(String[] args) {
System.out.println("list"+ kpilist.FindListKpi(1));
}
結果:
list [Number Of Closed issues, Number Of Opened issues]
所以在方法getMyListKPIs的問題,其實誤差正是在proprity「ID用戶」,這proprity我已經通過它從另一個bean值:
<managed-bean>
<managed-bean-name>ToolsKPI</managed-bean-name>
<managed-bean-class>DAOKPI.ToolsKPI</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>iduser</property-name>
<property-class>java.lang.Integer</property-class>
<value>#{BeanTools.iduser}</value>
</managed-property>
</managed-bean>