我有一个从DB填充的数据表,其中init函数具有postconstruct注释,问题是当我删除表中的一行时,即使实际上从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"));}
}
&#13;
<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>
&#13;
答案 0 :(得分:0)
我建议将用于填充数据表的代码放入其自己的方法中,以便在必要时通过@PostConstruct,action方法和/或Ajax方法调用它。