【发布时间】:2017-03-08 02:32:10
【问题描述】:
我有一个从 DB 填充的数据表,该数据表使用具有 postconstruct annotaion 的 init 函数,问题是当我删除表中的一行时,即使该实例实际上已从 DB 中删除,表数据也不会改变,所以我是想知道我是否可以再次执行 init 函数,以便它从 DB 中获取新数据并使用 ajax 将它们放入 datTable 中。
@ManagedBean
@SessionScoped
public class Compte implements Serializable{
/**
*
*/
private static final long serialVersionUID = -7177239517089845251L;
private int id_compte;
private int id_agence;
private int id_client;
private String num_compte;
private double solde;
private String date_creation_compte;
public ArrayList<Compte> comptes;
dao d = new dao();
public Compte() {
super();
// TODO Auto-generated constructor stub
}
@PostConstruct
public void init() {
ExternalContext ec =
FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) ec.getSession(false);
if(session.getAttribute("idagence")!=null){
comptes=d.getComptesAgc((String)session.getAttribute("login"));
}else{
comptes=d.getComptes((String)session.getAttribute("login"));}
}
<ui:composition template="./WEB-INF/template/template.xhtml">
<ui:param name="titre" value="Liste de Comptes"/>
<ui:define name="content">
<ice:form id="form">
<style type="text/css">
.ui-datatable-odd {
background-color:lightgray !important;
background-position-y: -1400px;
}
</style>
<ace:dataTable id="cptTable" value="#{compte.comptes}"
var="cpt" paginator="true" paginatorPosition="bottom" rows="10">
...
</ace:dataTable>
【问题讨论】:
-
解决方案是更新你的dataTable,而不是
brings the new data from DB and put them in the datTable using ajax -
uhhmmmm 通过调用 postConstruct 注释方法?