如何填充select onemenu JSF



我想从数据库中填充一个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;
}

结果:列表ttttttttttltttttttt tttttt[]

我已经测试了我的方法"FindListKpi",它运行良好:

public static void main(String[] args) {
System.out.println("list"+ kpilist.FindListKpi(1));
}

结果:

list [Number Of Closed issues, Number Of Opened issues]

因此,方法getMyListKPI中的问题,事实上错误正是在属性"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> 

你好,我已经解决了文件faces-config中的错误,我的托管属性是错误的,事实上,为了保持属性的值,配置是:

iduserjava.lang.Integer#{BeanTools.iduser}

相关内容

  • 没有找到相关文章

最新更新