【发布时间】:2011-01-12 18:41:58
【问题描述】:
我正在使用 JSF2.0 和 Primefaces 2.2RC2 运行应用程序
我已经在我的项目上运行了分析器,并确定存在来自 UISelectItems 列表的瓶颈。该列表在我的应用程序中的每个操作中被填充了 6 次。
UISelectItem 列表被填充到名为 getCountryList() 的 getter 方法中,它看起来像这样
public UISelectItems getCountryList() throws Exception {
Collection List = new ArrayList();
List<Countries> c_list = myDao.getCountryList();
for( QcardCountries c : c_list ) {
list.add(new SelectItem(c.getCountryId().toString(), c.getCountryName());
}
UISelectItems countries = new UISelectItems();
countries.setValue(list);
return countries;
}
当我像这样调用视图时这有效
<f:selectItems binding="#{myBean.countryList}" />
但对于我在应用程序中所做的每个按钮或操作,它再次被调用 6 次。
然后我尝试将 List 的创建移动到在 @PostContruct 上调用的方法中,但是当我这样做时,列表在我使用时不会显示
<f:selectItems binding="#{myBean.countryList}" />
它只是显示为空。有谁知道如何正确创建一个列表,以便它只创建一次,并且可以在整个用户会话中调用以填充下拉列表?
【问题讨论】:
标签: java jsf jsf-2 primefaces