Hello!
I am trying to create a table with data. If I klick on a record one value of this record the pid should be displayed somewhere. But however if I try to get the value of the selected record I get an null pointer exception. I hope someone can help me.
This is the code of the table:
public class PowershellGrid {
private static final long serialVersionUID = -182164459252797609L;
private Table grid;
private Window mainWindow;
private PowershellCommandContainer dataSource = PowershellCommandContainer.createContainer();
public PowershellGrid(Window mainWindow){
this.mainWindow = mainWindow;
}
public PowershellCommandContainer getDataSource() {
return dataSource;
}
public Table createPowershellGrid(){
System.out.println("Hallo!!!!!!");
grid = new Table();
grid.setWidth("650px");
grid.setColumnCollapsingAllowed(false);
grid.setSelectable(true);
grid.setImmediate(true);
grid.setMultiSelect(false);
grid.setContainerDataSource(this.getDataSource());
grid.setVisibleColumns(PowershellCommandContainer.NATURAL_COL_ORDER);
grid.setColumnHeaders(PowershellCommandContainer.COL_HEADERS_ENGLISH);
grid.addListener(new Table.ValueChangeListener(){
private static final long serialVersionUID = -1661124568210657394L;
@Override
public void valueChange(ValueChangeEvent event) {
System.out.println("Hallo 2!!!!!!");
mainWindow.getWindow().showNotification("Selected: "+grid.getValue());
}});
return grid;
}
}
This is the code of the container:
public class PowershellCommandContainer extends BeanItemContainer<PowershellCommand> implements Serializable {
private static Logger log = Logger.getLogger(PowershellCommandContainer.class);
private static final long serialVersionUID = -7369746537444565111L;
/**
* Natural property order for Person bean. Used in tables and forms.
*/
//public static final Object[] NATURAL_COL_ORDER = new Object[]
{"pid", "creationDate", "powershellExe", "powershellCommand", "shortDescription", "longDescription" };
public static final Object[] NATURAL_COL_ORDER = new Object[]
{"pid", "creationDate", "shortDescription" };
/**
* "Human readable" captions for properties in same order as in
* NATURAL_COL_ORDER.
*/
//public static final String[] COL_HEADERS_ENGLISH = new String[]
{"PID", "Creation date", "Powershell exe", "Powershell command", "Short description", "Long description" };
public static final String[] COL_HEADERS_ENGLISH = new String[]
{"PID", "Creation date", "Short description" };
public PowershellCommandContainer() throws InstantiationException,
IllegalAccessException {
super(PowershellCommand.class);
}
public static PowershellCommandContainer createContainer(){
try {
PowershellCommandContainer cont = new PowershellCommandContainer();
List<PowershellCommand> commands = PowershellCommandHibernate.getPowershellCommandList();
for(int i = 0; i<commands.size(); i++){
cont.addItem(commands.get(i));
}
return cont;
}
catch(Exception e){
log.error(e.getMessage());
return null;
}
}
}
Thanks!