我正在做一个使用 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>
现在,我必须在其他选项卡视图中显示与上面提到的相同选项卡的相同数据,唯一的事情是现在我必须在饼图中显示。现在在饼图中,我使用的是相同的列表。因此,它将再次从数据库中获取数据并浪费时间。为了解决这个问题,我创建了其他三个列表,并且只给出了之前列表的参考。所以,现在没有数据库获取发生。
应用参考的代码是:
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>
这背后应该是什么原因?