[英]seam action method executed twice?
我目前正在从事接缝项目,但遇到了问题。
我刚刚创建了一个新页面(一个名为MyPage.xhtml的xhtml)。 在xhtml我的代码中,您可以找到命令按钮和aa:repeater来显示我的数据:
<!-- input fields that are filters for my table shown below -->
<h:commandButton value="View details" action="/MyPage.xhtml"/>
<rich:panel rendered=#{myAction.showDetails}>
<a:repeat value="#{myAction.findRecords()}" var="record">
<!-- Some of my code to display a table, nothing fancy -->
</a:repeat>
</rich:panel>
在我的行动中,我有这个:
@DataModel
private List<MyEntity> records = new ArrayList<MyEntity>();
public List<MyEntity> findRecords() {
//Do some query
Query query = entityManager.createNamedQuery("myEntityQuery");
records = query.getResultList();
return records;
}
页面的工作方式如下:
为什么要执行两次? 如何将其限制为一次? 现在,它花费了我们很多性能。
r
短剑
该方法最有可能在视图重建(还原视图阶段)期间和再次渲染(渲染响应阶段)期间执行。
尝试缓存该方法是否已经执行或仅在单击按钮时才执行,并提供一个简单的获取方法来传递数据。
通常要注意的是,仅在需要时(缓存结果)或在调用应用程序阶段(通常使用action
或actionListener
),才应执行数据库查询之类的昂贵操作
我会做这样的事情,并使用范围来存储数据。 如果您重复使用类似的函数,它将在重复中的每一行访问该方法。
<h:commandButton value="View details" action="/MyPage.xhtml"/>
<rich:panel rendered=#{myAction.showDetails}>
<a:repeat value="#{records}" var="record">
<!-- Some of my code to display a table, nothing fancy -->
</a:repeat>
</rich:panel>
@Out
private List<MyEntity> records = new ArrayList<MyEntity>();
@Factory(value="records")
public void findRecords() {
//Do some query
Query query = entityManager.createNamedQuery("myEntityQuery");
records = query.getResultList();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.