Peppe-/PagedTable — Issue #8: PagedTable Dymanic Row Insert
Author: rajuprabu
Created: 2012-03-07 16:55:23+00:00
State: open

I am using PagedTable control and i am facing problem in dynamically adding row in the Table. When I add row dynamically, it is not reflected in the table UI, I have to either change the Items per Row (int the UI) or click on the column header to see the inserted row in the PagedTable.

I am using PagedTable 0.6.3 and my application is deployed inside JBOSS AS 7.0.1 container.

Here is my code:

private void initUI()
{
final Action ACTION_ADD = new Action("Add");
final Action ACTION_EDIT = new Action("Edit");
final Action ACTION_CANCEL = new Action("Cancel");

final Action[] SELECT_MENU_ACTIONS = new Action[] { ACTION_ADD, ACTION_EDIT,ACTION_CANCEL};
final Action[] NULL_MENU_ACTIONS = new Action[] { ACTION_ADD, ACTION_CANCEL};

final PagedTable table = new PagedTable("");
table.setWidth("100%");
table.setSelectable(true);
table.setMultiSelect(false);
table.setImmediate(true); // react at once when something is selected

table.setContainerDataSource(getDSStructure());
table.setNullSelectionAllowed(false);
table.setColumnCollapsingAllowed(true);

// turn on column reordering and collapsing
table.setColumnReorderingAllowed(true);
table.setColumnCollapsingAllowed(true);

// set column headers
table.setColumnHeaders(new String[] {"ID","Name", "Short Name","Satus","ROD"});
table.setVisibleColumns(new Object[] {"id", "name","shortName", "status","rod"});

table.addActionHandler(new Action.Handler()
{
public Action[] getActions(Object target, Object sender)
{
Item selectedItem = table.getContainerDataSource().getItem(target);

if(selectedItem == null)
return NULL_MENU_ACTIONS;
else
{
return SELECT_MENU_ACTIONS;
}
}

public void handleAction(Action action, Object sender, Object target)
{
// TODO Auto-generated method stub
if (ACTION_ADD == action)
{
try
{
showAddForm(table); // Takes input and inset a new row in the PagedTable
}catch(Exception ex)
{
getWindow().showNotification(
"Error!", ex.getMessage(),
Notification.TYPE_ERROR_MESSAGE);
}
return;
}
else if (ACTION_EDIT == action)
{
g_selectedItem = table.getContainerDataSource().getItem(target);
if(g_selectedItem == null)
return;

// showEditForm();
return;
}

}
});

setWidth("100%");
loadTableRecords(table.getContainerDataSource());
addComponent(table);
addComponent(table.createControls());
table.setPageLength(5); // Call this method only after calling table.createControls();

}

private IndexedContainer getDSStructure()
{
IndexedContainer container = new IndexedContainer();

container.addContainerProperty("id", String.class,null);
container.addContainerProperty("name", String.class,null);
container.addContainerProperty("shortName", String.class,null);
container.addContainerProperty("status", String.class,null);
container.addContainerProperty("rod", String.class,null);

return container;
}

private void loadTableRecords(Indexed container ) throws Exception
{
Listlist = application.getNBBean().readAll();
for(int i=0;i