I’m using the Vaadin daily builds because I’m playing with the TreeTable add-in on one of my pages. I’m having problems with TreeTable and Table when selecting a row. If I’m outside the cached area, the selection of a row cause the Table to reposition to the top instead of staying on the selected row. I haven’t noticed this with any of the demos and was wondering if I’m doing something wrong or if there’s an issue with the daily builds or the HbnContainer add-on.
Below is a sample of one of my Tables and Layout…
Layout:
public class LogLayout extends VerticalLayout implements SessionManager {
public LogLayout() {
}
@Override
public void attach() {
super.attach(); // Must call.
attachVaadinTransactionListener();
//final TextField traceEditor = new TextField();
//final Label traceEditor = new Label();
final Table logTable = new LogTable();
this.addComponent(logTable);
final IndexedContainer traceContainer = new IndexedContainer();
traceContainer.addContainerProperty("traceLine", String.class, null);
final Table traceTable = new Table();
traceTable.setContainerDataSource(traceContainer);
traceTable.setColumnHeaders(new String[] { "Trace Line" });
traceTable.setSizeFull();
traceTable.setVisible(false);
this.addComponent(traceTable);
// traceEditor.setRows(20);
// traceEditor.setColumns(20);
//this.addComponent(traceEditor);
logTable.addListener(new Table.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (event.getProperty().getValue() != null) {
traceTable.removeAllItems();
try {
LoggingEventExceptionDAO lee = new LoggingEventExceptionDAO();
lee.startSession();
List<LoggingEventException> traceList = lee.getLoggingEventExceptionList((Long)event.getProperty().getValue());
lee.close();
for (LoggingEventException trace : traceList) {
Object id = traceTable.addItem();
traceTable.getContainerProperty(id, "traceLine").setValue(trace.getTraceLine());
}
} catch (Exception e) {
}
traceTable.setVisible(traceTable.size() > 0);
}
}
});
}
/**
* We are using session-per-request pattern with Hibernate. By using
* Vaadin's transaction listener we can easily ensure that session is closed
* on each request without polluting our program code with extra logic.
*/
private void attachVaadinTransactionListener() {
final Application parentApp = this.getApplication();
parentApp.getContext().addTransactionListener(new TransactionListener() {
@Override
public void transactionEnd(Application application,
Object transactionData) {
// Transaction listener gets fired for all (Http) sessions
// of Vaadin applications, checking to be this one.
if (application == parentApp) {
closeSession();
}
}
@Override
public void transactionStart(Application application,
Object transactionData) {
}
});
}
private void closeSession() {
Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
if (sess.getTransaction().isActive()) {
sess.getTransaction().commit();
}
if (sess.isOpen()) {
sess.close();
}
}
/**
* Used to get current Hibernate session. Also ensures an open Hibernate
* transaction.
*/
@Override
public Session getSession() {
Session currentSession = HibernateUtil.getSessionFactory()
.getCurrentSession();
if (!currentSession.getTransaction().isActive()) {
currentSession.beginTransaction();
}
return currentSession;
}
}
Table:
public class LogTable extends Table implements SessionManager {
/**
* Natural property order for Message. Used in tables and forms.
*/
public static final Object[] NATURAL_COL_ORDER = new Object[]
{
"timestmp", "loggerName", "levelString", "formattedMessage"};
/**
* "Human readable" captions for properties in same order as in
* NATURAL_COL_ORDER.
*/
public static final String[] COL_HEADERS_ENGLISH = new String[]
{
"Timestamp", "Logger", "Level", "Message"};
public LogTable () {
// size
this.setSizeFull();
this.setCacheRate(5);
this.addStyleName("striped cellborder");
this.setContainerDataSource(new HbnContainer<LoggingEvent>(LoggingEvent.class, this));
this.setVisibleColumns(NATURAL_COL_ORDER);
this.setColumnHeaders(COL_HEADERS_ENGLISH);
this.setSelectable(true);
this.setImmediate(true);
this.setSortContainerPropertyId("timestmp");
this.setSortDisabled(false);
this.setSortAscending(false);
this.addGeneratedColumn("timestmp", new DateColumnGenerator());
}
@Override
public Session getSession() {
Session currentSession = HibernateUtil.getSessionFactory()
.getCurrentSession();
if (!currentSession.getTransaction().isActive()) {
currentSession.beginTransaction();
}
return currentSession;
}
}
Thanks,
Rob