题
我做一个项目,我使用JSF 2.0&Primefaces UI组件。
有与突片,“日”,“周”和“月”标签视图组件。在所有选项卡,我要显示在每个条形图。出于同样的,我使用以下三种方法获取三甲之列。在下面的代码,UpdateCountHelper被获取从数据库中的数据。所以,UpdateCountHelper正在一些时间获取数据。
这是用于获取列表的代码:
public List<UpdateCount> getDayUpdateCounts() {
if (projectFlag == true) {
if (displayFlag == 1) {
dayUpdateCounts = UpdateCountHelper.getProjectUpdates(1);
} else {
dayUpdateCounts = UpdateCountHelper.getProjectUpdates(name, 1);
}
} else {
dayUpdateCounts = UpdateCountHelper.getResourceUpdates(userName, 1);
}
return dayUpdateCounts;
}
public List<UpdateCount> getMonthUpdateCounts() {
if (projectFlag == true) {
if (displayFlag == 1) {
monthUpdateCounts = UpdateCountHelper.getProjectUpdates(30);
} else {
monthUpdateCounts = UpdateCountHelper.getProjectUpdates(name, 30);
}
} else {
monthUpdateCounts = UpdateCountHelper.getResourceUpdates(userName, 30);
}
return monthUpdateCounts;
}
public List<UpdateCount> getWeekUpdateCounts() {
if (projectFlag == true) {
if (displayFlag == 1) {
weekUpdateCounts = UpdateCountHelper.getProjectUpdates(7);
} else {
weekUpdateCounts = UpdateCountHelper.getProjectUpdates(name, 7);
}
} else {
weekUpdateCounts = UpdateCountHelper.getResourceUpdates(userName, 7);
}
return weekUpdateCounts;
}
这是条形图的UI代码:
<p:panel id="Chart">
<p:tabView dynamic="false" cache="false">
<p:tab title="Day">
<p:panel id="chartDayPanel">
<center>
<h:outputText id="projectWiseDayText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Day Update"/>
<p:columnChart id="projectWiseDayUpdateChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.dayUpdateCounts}" var="dayWiseUpdate" xfield="#{dayWiseUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Project Wise Current Day Update" value="#{dayWiseUpdate.noUpdates}"/>
</p:columnChart>
<h:outputText id="resourceWiseDayText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Day Update"/>
<p:columnChart id="resourceWiseDayUpdateChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.dayUpdateCounts}" var="dayWiseResourceUpdate" xfield="#{dayWiseResourceUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Resource Wise Current Day Update" value="#{dayWiseResourceUpdate.noUpdates}"/>
</p:columnChart>
</center>
</p:panel>
</p:tab>
<p:tab title="Week">
<p:panel id="chartWeekPanel">
<center>
<h:outputText id="projectWiseWeekText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Week Update"/>
<p:columnChart id="projectWiseWeekUpdateChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.weekUpdateCounts}" var="weekWiseUpdate" xfield="#{weekWiseUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Project Wise Current Week Update" value="#{weekWiseUpdate.noUpdates}"/>
</p:columnChart>
<h:outputText id="resourceWiseWeekText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Week Update"/>
<p:columnChart id="resourceWiseWeekUpdateChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.weekUpdateCounts}" var="weekWiseResourceUpdate" xfield="#{weekWiseResourceUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Resource Wise Current Week Update" value="#{weekWiseResourceUpdate.noUpdates}"/>
</p:columnChart>
</center>
</p:panel>
</p:tab>
<p:tab title="Month">
<p:panel id="chartMonthPanel">
<center>
<h:outputText id="projectWiseMonthText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Month Update"/>
<p:columnChart id="projectWiseMonthUpdateChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.monthUpdateCounts}" var="monthWiseUpdate" xfield="#{monthWiseUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Project Wise Current Month Update" value="#{monthWiseUpdate.noUpdates}"/>
</p:columnChart>
<h:outputText id="resourceWiseMonthText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Month Update"/>
<p:columnChart id="resourceWiseMonthUpdateChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.monthUpdateCounts}" var="monthWiseResourceUpdate" xfield="#{monthWiseResourceUpdate.name}" height="200px" width="640px">
<p:chartSeries label="Resource Wise Current Month Update" value="#{monthWiseResourceUpdate.noUpdates}"/>
</p:columnChart>
</center>
</p:panel>
</p:tab>
</p:tabView>
</p:panel>
现在,我具有上述&唯一提到与同一突出部,以显示在其他TabView的相同的数据现在是我在饼图显示量。现在,在饼图,我使用的是相同的列表。因此,它将会再次获取来自数据库和浪费时间的数据。为了解决我创建了其它三个列表和给只有那些先前列出的参考这个问题。所以,现在没有数据库取出发生。
代码用于施加基准是:
public List<UpdateCount> getPieDayUpdateCounts() {
pieDayUpdateCounts = dayUpdateCounts;
return pieDayUpdateCounts;
}
public List<UpdateCount> getPieMonthUpdateCounts() {
pieMonthUpdateCounts = monthUpdateCounts;
return pieMonthUpdateCounts;
}
public List<UpdateCount> getPieWeekUpdateCounts() {
pieWeekUpdateCounts = weekUpdateCounts;
return pieWeekUpdateCounts;
}
但是,在这里出现的问题是其中的标签是使被显示,但其它剩余2个标签没有显示任何图表仅图表。
有关UI的代码是:
<p:tabView dynamic="false" cache="false">
<p:tab title="Day">
<center>
<p:panel id="pieChartDayPanel">
<h:outputText id="projectWiseDayPieChartText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Day Update"/>
<p:pieChart id="projectWiseDayUpdatePieChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.dayUpdateCounts}" var="dayWisePieUpdate" categoryField="#{dayWisePieUpdate.name}" dataField="#{dayWisePieUpdate.noUpdates}" height="200" width="200"/>
<h:outputText id="resourceWiseDayPieChartText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Day Update"/>
<p:pieChart id="resourceWiseDayUpdatePieChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.dayUpdateCounts}" var="dayWiseResourcePieUpdate" categoryField="#{dayWiseResourcePieUpdate.name}" dataField="#{dayWiseResourcePieUpdate.noUpdates}" height="200" width="200"/>
</p:panel>
</center>
</p:tab>
<p:tab title="Week">
<center>
<p:panel id="pieChartWeekPanel">
<h:outputText id="projectWiseWeekPieChartText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Week Update"/>
<p:pieChart id="projectWiseWeekUpdatePieChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.weekUpdateCounts}" var="weekWisePieUpdate" categoryField="#{weekWisePieUpdate.name}" dataField="#{weekWisePieUpdate.noUpdates}" height="200" width="200"/>
<h:outputText id="resourceWiseWeekPieChartText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Week Update"/>
<p:pieChart id="resourceWiseWeekUpdatePieChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.weekUpdateCounts}" var="weekWiseResourcePieUpdate" categoryField="#{weekWiseResourcePieUpdate.name}" dataField="#{weekWiseResourcePieUpdate.noUpdates}" height="200" width="200"/>
</p:panel>
</center>
</p:tab>
<p:tab title="Month">
<center>
<p:panel id="pieChartMonthPanel">
<h:outputText id="projectWiseMonthPieChartText" rendered="#{systemUtilizationServiceBean.projectFlag}" value="Project Wise Month Update"/>
<p:pieChart id="projectWiseMonthUpdatePieChart" rendered="#{systemUtilizationServiceBean.projectFlag}" value="#{systemUtilizationServiceBean.monthUpdateCounts}" var="monthWisePieUpdate" categoryField="#{monthWisePieUpdate.name}" dataField="#{monthWisePieUpdate.noUpdates}" height="200" width="200"/>
<h:outputText id="resourceWiseMonthPieChartText" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="Resource Wise Month Update"/>
<p:pieChart id="resourceWiseMonthUpdatePieChart" rendered="#{systemUtilizationServiceBean.resourceFlag}" value="#{systemUtilizationServiceBean.monthUpdateCounts}" var="monthWiseResourcePieUpdate" categoryField="#{monthWiseResourcePieUpdate.name}" dataField="#{monthWiseResourcePieUpdate.noUpdates}" height="200" width="200"/>
</p:panel>
</center>
</p:tab>
</p:tabView>
应该是什么这背后的原因是什么?
解决方案
而不是试图让你列表的多个副本,使用JSF作用域时/他们是如何获取往往管理。
范围支持bean到RequestScoped或ViewScoped,创建从数据库获取的列表的方法(如果使用CDI,然后注释的方法@PostConstruct,否则调用它与PreRenderViewEvent或在构造本身)。现在,通过简单的getter访问列表。
不隶属于 StackOverflow