gpt4 book ai didi

java - JSF 2.0 问题

转载 作者:行者123 更新时间:2023-12-04 06:51:35 25 4
gpt4 key购买 nike

我正在做一个使用 JSF 2.0 和 Primefaces UI 组件的项目。

有一个带有选项卡的选项卡 View 组件,“天”,“周”和“月”。在所有选项卡中,我必须在每个选项卡中显示条形图。同样,我使用以下三种方法获取三个列表。在以下代码中,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 访问您的列表。

关于java - JSF 2.0 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3043642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com