Reputation: 608
I would like to create wicket page where is displayed table with data from database, under this table, there is form which create another objects into database. When I save object, page does not refresh, so in table I cannot see new row. If I understood it correctly, to solve this issue I have to use ajax. I found guide (https://cwiki.apache.org/confluence/display/WICKET/How+to+repaint+a+ListView+via+Ajax) and created something similar in my project, but it does not work and I can not find the reason why does it not work. I found that another people had problems that they tried to actualize just only rows/panel, but it is not my case. I do not get even any exception, just it does nothing. Could you please give me an advice?
.java file
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 file
<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>
Upvotes: 1
Views: 142
Reputation: 17513
The problem is in:
List<Rezervace> rezervace = rezervaceDao.getAllRezervace();
ListView listview = new ListView("rezervaceList", rezervace)
The list view initializes itself with a static list. It should instead ask the DB for new data on every refresh.
Read https://cwiki.apache.org/confluence/display/WICKET/Working+with+Wicket+models#WorkingwithWicketmodels-DynamicModels about static vs. dynamic models.
Upvotes: 5