I got a problem with buttons in a datatable. The table is populated by calling myEventInit and directed to the page MyEvents.xhtml (se code below). Data for the table is provided by lessonlist. I put a breakpoint on the line for getLessonList. First time the page I rendered lessonList got some data. But if I trigger a button in the table lessonList is null, setLesson2delete is not called and no action is done. I really don't get why lessonList on the session scoped bean is empty.
Here is the xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<ui:composition template="/templates/BasicTemplate.xhtml">
<ui:define name="content">
<div style="background-color: #cfcfcf;
border: 1px black dotted; width:95%; margin: 10px;">
<h:form id="deleteLessons">
<p:dataTable value="#{schb.lessonList}" var="lesson" id="lessonlist" >
<p:column>
<f:facet name="header">
<h:outputText value="Sal" />
</f:facet>
<h3>
<h:outputText value="#{lesson.lessonInfo}" />
</h3>
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="Dina bokningar" />
</f:facet>
<p:commandButton style="width:450px; font-size:15px;height:23px;"
update="@this"
value="Radera #{lesson.lessonInfo}">
<f:setPropertyActionListener value="#{lesson.uuid}"
target="#{schb.lesson2delete}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
</div>
</ui:define>
</ui:composition>
</h:body>
</html>
and the backing bean:
package jkpgweb.managedbeans;
@ManagedBean(name = "schb")
@SessionScoped
public class SchemBean2 extends BeanTemplate {
Date start = new Date(1452765600000L), stop;
int lengthOfLesson = 70;
int searchweek;
String searchklass, requestedDay, requestedGroup;
String room2book;
ArrayList<sbasLesson> lessonList;
public String myEventsInit() {
ObjectContainer localdb = dbConnector.connDB();
Query q = localdb.query();
q.constrain(sbasLesson.class);
q.descend("Teacher").constrain(this.getCurrUser().getUsername()).contains();
q.descend("type").constrain('M');
ObjectSet<sbasLesson> res;
res = q.execute();
lessonList = new ArrayList<sbasLesson>();
lessonList.addAll(res);
return "/Teacher/myEvents.xhtml";
}
public void setLesson2delete(long duuid) {
ObjectContainer db = dbConnector.connDB();
Query q = db.query();
q.constrain(sbasLesson.class);
q.descend("uuid").constrain(duuid);
db.close();
}
@PostConstruct
public ArrayList<sbasLesson> getLessonList() {
return lessonList;
}
public void setLessonList(ArrayList<sbasLesson> lessonList) {
this.lessonList = lessonList;
}
}