2014-12-19 72 views
1

我想創建wicket頁面,其中顯示的表與數據庫中的數據有關,在這個表下,有創建另一個對象到數據庫的窗體。當我保存對象時,頁面不刷新,所以在表格中我看不到新的一行。 如果我理解正確,要解決此問題,我必須使用ajax。我找到了指南(https://cwiki.apache.org/confluence/display/WICKET/How+to+repaint+a+ListView+via+Ajax)並在我的項目中創建了類似的東西,但它不起作用,我無法找到它不起作用的原因。我發現另一個人有問題,他們試圖實現只有行/面板,但它不是我的情況。我甚至沒有任何異常,只是它什麼都不做。你能給我一個建議嗎?Ajax沒有在窗口中實現listview

java文件

public class ListPanel extends Panel { 
    private static final long serialVersionUID = 6953172817971228490L; 

    @SpringBean 
    RezervaceDao rezervaceDao; 

    public ListPanel(String id) { 
     super(id); 

     List<Rezervace> rezervace = rezervaceDao.getAllRezervace(); 
     ListView listview = new ListView("rezervaceList", rezervace) { 
      private static final long serialVersionUID = 3659733406689720345L; 

      protected void populateItem(ListItem item) { 
       Rezervace r = (Rezervace) item.getModelObject(); 
       item.add(new Label("casRezervace", r.getCasRezervace())); 
       item.add(new Label("jmeno", r.getJmeno())); 
       item.add(new Label("adresa", r.getAdresa())); 
       item.add(new Label("telefon", r.getTelefon())); 
      } 
     }; 
     listview.setReuseItems(true); 

     // encapsulate the ListView in a WebMarkupContainer in order for it to 
     // update 
     WebMarkupContainer listContainer = new WebMarkupContainer("obal"); 
     // generate a markup-id so the contents can be updated through an AJAX 
     // call 
     listContainer.setOutputMarkupId(true); 
     listContainer 
       .add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(3))); 
     // add the list view to the container 
     listContainer.add(listview); 
     // finally add the container to the page 
     add(listContainer); 

    } 
} 

.html文件

<wicket:panel> 
    <div wicket:id="obal"> 
     <table> 
      <tr> 
       <th>Čas návštěvy</th> 
       <th>Jméno a Příjmení</th> 
       <th>Adresa</th> 
       <th>Kontaktní telefon</th> 
      </tr> 
      <tr wicket:id="rezervaceList"> 
       <td><span wicket:id="casRezervace"></span></td> 
       <td><span wicket:id="jmeno"></span></td> 
       <td><span wicket:id="adresa"></span></td> 
       <td><span wicket:id="telefon"></span></td> 
      </tr> 
     </table> 
    </div> 
</wicket:panel> 

回答

5

的問題是:

List<Rezervace> rezervace = rezervaceDao.getAllRezervace(); 
ListView listview = new ListView("rezervaceList", rezervace) 

列表視圖初始化本身的靜態列表。它應該向數據庫詢問每次刷新時的新數據。

閱讀關於靜態與動態模型的https://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models#WorkingwithWicketmodels-DynamicModels

+1

是的,這將起作用。小記:我會打電話給列表是'固定'(因爲「靜態」可能會導致與'靜態'混淆) – RobAu 2014-12-19 07:59:10

+0

非常感謝,現在它完美的工作! – Eleer 2014-12-19 11:51:13