我想从我的数据库填充一个selectonemenu,但总是列表为空 这是我的代码:
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中的问题,实际上错误完全是在“iduser”的默认情况下,这个例子我从另一个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>
答案 0 :(得分:0)
你好我已经解决了错误在文件faces-config的问题,我的托管所有权是错误的,实际上是为了保存配置属性的值:
ID用户 为java.lang.Integer #{} BeanTools.iduser