Problems related to Tables and SQLContainer updates

I having some problems related to editing data in a table. Some of this is probably due to my not quite understanding how the system is supposed to work - I’d be grateful for some sample code, a pointer to a tutorial or appropriate documentation…

I have a database table containing an integer id and a string (name). I can load that table into a Vaadin Table and display it. Using a couple of buttons, I can select a table entry and delete it, and I can add a new entry into the database. All that is working properly.

Now I want to add the ability to edit a entry and update the database record. And here, everything falls apart.

My code looks like this:

tbl_BUNames = new Table();
tbl_BUNames.setHeight(“450px”);
tbl_BUNames.setWidth(“350px”);
tbl_BUNames.setSelectable(true);
// tbl_BUNames.setEditable(true);
tbl_BUNames.setImmediate(true);
sqc_BUNames = app.getDbMgr().getSqc_BUNames();
tbl_BUNames.setContainerDataSource(sqc_BUNames);
tbl_BUNames.addListener(new Property.ValueChangeListener(){
private static final long serialVersionUID = 1L;

public void valueChange(ValueChangeEvent event){
    BuName bu = null;
    Logger.info("Selected: " + tbl_BUNames.getValue());
    bu = app.getDbMgr().getBUById(tbl_BUNames.getValue());
    if(bu != null){
        tbl_BUNames.setEditable(true);
        Logger.info("BU: Id:" + bu.getId() + "   Name: " + bu.getBuName());
    }
    else{
        Logger.info("Nothing selected - make table non-editable");
        tbl_BUNames.setEditable(false);
    }
}

});

When I run this code, my log file shows the following - Basically, if I select a row in the table, it prints the ‘selected’ message, but the table does NOT become editable. If I then click the same row (row 8, in the log file below) it becomes unselected, and I get a critical, internal error message on the screen. The log file entry is shown at the bottom of this post. It looks to be inside the Table object itself. So am I doing something wrong? Do I need to force a refresh on the screen after changing the edit mode? Note that if I uncomment the setEditable(true) statement at the top of my code, and comment out the setEditable statements in the listener, the table comes up editable - I can type into the name fields and the changes show up on the screen…

My second question - If I change the code to start the table in editable mode - then if I simply change the value of one of the name fields, the changeValueEvent does not fire - how do I detect that an entry has been changed, and what do I need to do to push that change back into the database? I am using SQLContainer as the backing store here.

Thanks for any help you can give me…

nbc

======= Log file - shows internal error when unselecting a table entry ==========
Selected: 9
BU: Id:9 Name: Shared Services
Selected: 8
BU: Id:8 Name: NetSec ******* After this, click row 8 a second time to unselect it - and get error…
Apr 1, 2011 11:44:35 AM com.vaadin.Application terminalError
SEVERE: Terminal error:
java.lang.NullPointerException
at com.vaadin.ui.Table.getVisibleItemIds(Table.java:3080)
at com.vaadin.ui.AbstractSelect.changeVariables(AbstractSelect.java:463)
at com.vaadin.ui.Table.changeVariables(Table.java:2023)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1297)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1217)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:733)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:662)
Apr 1, 2011 11:44:35 AM com.vaadin.Application terminalError
SEVERE: Terminal error:
java.lang.NullPointerException
at com.vaadin.ui.Table.paintContent(Table.java:2317)
at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:754)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(AbstractCommunicationManager.java:952)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:839)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:765)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:662)

Hi Neil!

I stumbled upon a possible solution to your second question about updating the container via the table. It’s a fairly simple code but have you tried something like below? I know it seems pretty basic but from what I’ve been reading into this could help. Also you could try the Container.PropertySetChangeListener.

public class File implements Property.ValueChangeListener {
	
	private Table table;
	
	public File(){
		table = new Table("awesome table", dataSourceContainer);
		table.addListener((Property.ValueChangeListener)this);
                                table.setWriteThrough(true);
	}

	public void propertyValueChange(ValueChangeEvent event) {
		if(event.getProperty()==tableProperty){
			table.commit();
		}
		
	}
}

Hi DeAnna,

I actually did end up with something close to what you suggested and it does work. I’m still having some problems with SQLContainer - it looks like I’ve stumbled across at least one bug in the code, and I’m still waiting to hear from someone more knowledgeable about whether my problems with cache size are another bug or if I’m using the container incorrectly. But I have managed to get this part of my system running.

Thanks for the suggestion.

nbc