我有支持bean:
@ManagedBean
@ViewScoped
public class MyBean{
private boolean needUpdateData;
private List<Object> data;
//Other fields, GET, SET
public void doDataSearch(){
needUpdateData = true;
}
public List<Object> retrieveData(){
if(!needUpdateData)
return data;
//Otherwise, retrieve the data from a database from scratch
}
public void refresh(){
needUpdateData = false;
}
}
以及以下标记:
<h:commandButton action="#{myBean.doDataSearch}">
<!-- Paging and the table representing the data -->
我需要仅在点击commandButton
时才需要更新数据,即点击commandButton
并检索我们将needUpdateData
设置为false的数据。
我会使bean实现PhaseListener
如下:
@Override
public void afterPhase(PhaseEvent event) {
needUpdateSummary = false;
}
@Override
public void beforePhase(PhaseEvent event) {
}
@Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
但我不确定。它被认为是一种很好的JSF方式吗?