2011-12-19 74 views
1

我使用PF 3.0RC1與JSF 2.0。Refresh行刪除後數據表

我有一個數據表,並在每一行我有一個刪除按鈕。只要我按下刪除相應的行從數據庫中刪除,但數據表不會刷新。它仍然顯示舊的一組行。我怎樣才能讓數據表被刷新?

下面是代碼

<h:form id="form"> 
    <p:dataTable value="#{myController.displayList}" var="item" id="tbl"> 
     <p:column> 
     <p:commandButton image="icon icon-delete" 
          id="del" action="#{myController.del}" 
          update="@form">  
      <f:setPropertyActionListener value="#{item}" 
       target="#{myController.selected}" for="del"/> 
     </p:commandButton> 
     </p:column> 
    </p:dataTable> 
    </h:form> 

DisplayList中是

private List<Image> displayList = new ArrayList<Image>(); 

public List<Image> getDisplayList() { 
     Student std = (Student) getSelected; 
     displayList = this.ejbFacade.getImages(std.getId()); // this method gets the list of images which has status = 1 
     return displayList; 
} 

public void setDisplayList(List<Image> displayList) { 
    this.displayList = displayList; 
} 

//這是其中設置標誌爲圖像爲0德爾方法(當從圖按下刪除圖標) public void del(){0} {0} {0} selected.setActiveStatus(0); MyController myController =(MyController)facesContext.getApplication()。getELResolver()。 getValue(facesContext.getELContext(),null,「myController」);
displayList.clear(); myController.getFacade()。edit(selected); }

+0

你使用緩存的連接池(比如公共DBCP)?可能問題在那裏。 – AValchev 2011-12-19 14:46:04

回答

2

我敢肯定你是從數據庫中刪除行,但dataTable records list沒有更新/刷新。 更新您記錄列表,方法是從列表中刪除已刪除的記錄,或者使用數據庫中的數據重新填充列表(儘管這會消耗一點資源)。 讓我看看java代碼!

PS:又恭喜你問了千分之一 primefaces問題! :)所以我在您的處置......

+0

我試圖將該標誌設置爲0,以便圖像不顯示在數據表中。在del方法中,我將標誌設置爲0,並在數據表查詢中獲取active = 1的圖像。這裏是del方法'public void del()selected.setActiveStatus(false); FacesContext facesContext = FacesContext.getCurrentInstance(); MyController myController =(MyController)facesContext.getApplication()。getELResolver()。 getValue(facesContext.getELContext(),null,「myController」); myController.getFacade()。edit(selected); }' – goodprg 2011-12-19 15:18:46

+0

@ user1097366請編輯你的問題,就像你把xhtml代碼一樣發佈代碼...此外,我不明白這個標誌是什麼,發佈'displayList'方法 – spauny 2011-12-19 15:21:57

+0

我根據你的建議更新了我的Q.請指教。 – goodprg 2011-12-20 07:31:39

0

如果顯示列表是從表

然後

在你需要做的

刪除方法保存的值列表「設置刪除行的id到索引變量」

然後執行:

displayList.remove(index); 

,然後刪除數據庫

行還嘗試加入process="@this"到命令