Java seam动作方法执行两次?
我目前正在做一个seam项目,遇到了一个问题 我刚刚创建了一个新页面(一个名为MyPage.xhtml的xhtml)。 在xhtml我的代码中,您可以找到一个命令按钮和一个:中继器来显示我的数据:Java seam动作方法执行两次?,java,seam2,Java,Seam2,我目前正在做一个seam项目,遇到了一个问题 我刚刚创建了一个新页面(一个名为MyPage.xhtml的xhtml)。 在xhtml我的代码中,您可以找到一个命令按钮和一个:中继器来显示我的数据: <!-- input fields that are filters for my table shown below --> <h:commandButton value="View details" action="/MyPage.xhtml"/> <rich:pa
<!-- 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;
}
@DataModel
私有列表记录=新的ArrayList();
公共列表findRecords(){
//询问
Query Query=entityManager.createNamedQuery(“myEntityQuery”);
records=query.getResultList();
退货记录;
}
这是页面的工作方式:
Dirk该方法很可能是在视图重建(恢复视图阶段)和再次渲染(渲染响应阶段)期间执行的 尝试缓存方法是否已经执行,或者仅在单击按钮时执行,并提供一个简单的getter来传递数据
一般来说,您应该只在需要时(缓存结果)或在调用应用程序阶段(通常使用
action
或actionListener
)执行诸如数据库查询之类的代价高昂的操作。我会这样做,并使用作用域存储数据。如果使用repeat中的函数,它将访问repeat中每一行的方法
<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();
}
@出去
私有列表记录=新的ArrayList();
@工厂(value=“记录”)
公共无效文件记录(){
//询问
Query Query=entityManager.createNamedQuery(“myEntityQuery”);
records=query.getResultList();
}