我认为我的问题与BalusC的答案有关:Evaluation of EL during view build time
我正在尝试使用JSF2复合组件显示一系列Primefaces,并将自定义BarCharts对象作为属性传入。Chart对象包含图表名称、标题和对DAO对象的调用以检索数据模型。这是我的复合组件。
<composite:interface>
<composite:attribute name="chart" />
</composite:interface>
<composite:implementation>
<p:barChart id="#{cc.attrs.chart.name}" title="#{cc.attrs.chart.title}" value="#{cc.attrs.chart.model}"
style="width:300px" legendPosition="ne" xaxisAngle="45"/>
</composite:implementation> 当Primefaces呈现barchart对象时,它为barchart对象调用了三次getValue(),并且正如上面的链接所解释的,只存储了EL表达式"#{cc.attrs.chart.model}“。这导致每次Primefaces在内部调用getValue时都会进行新的模型评估,因此需要对数据库进行三次往返。
有没有什么方法可以计算一次cc.attrs.chart.model并将其用作图表的值属性?
我想我可以使用一个图表UI组件和绑定,但我希望在我的视图中定义尽可能多的图表属性,这样感觉就不对了?
发布于 2013-11-05 17:16:05
为什么不使用延迟加载呢?
像这样:
public Object getValue() {
if(this.value == null) {
// do value loading here
}
return this.value;
}https://stackoverflow.com/questions/19785074
复制相似问题