final ListConfigurationVO.Type type = getType();
UserVO user = (UserVO)request.getSession().getAttribute(Globals.USER_KEY);
UserConfiguration conf = (UserConfiguration)request.getSession().getAttribute(Globals.CONFIGURATION_KEY);
ListConfigurationVO choosenList = (ListConfigurationVO)panel.getAttribute("choosenList");
if(panel.getAttribute("listConfigurations") == null) {
List<ListConfigurationVO> listConfigurations = new ListConfigurationDAO().getByTypeAndUser(type, user);
if(!listConfigurations.isEmpty()) {
ListBean bean = new ListBean();
for(ListConfigurationVO vo : listConfigurations) {
List<ListConfigurationVO> group = bean.getGroups().get(vo.getUser() == null);
group.add(vo);
}
if(!listConfigurations.contains(choosenList)) {
if(log.isDebugEnabled())
log.debug("list is not yet available: "+choosenList);
panel.removeAttribute("choosenList");
}
panel.setAttribute("listConfigurations", bean);
}
}
if(form.getDoChooseList() != null) {
if(log.isDebugEnabled())
log.debug("load new list configuration: "+form.getListId());
panel.removeAttribute(TABLE_KEY);
choosenList = new ListConfigurationDAO().getById(form.getListId());
form.setDoChooseList(null);
} else if(panel.getAttribute(TABLE_KEY) == null) {
if(log.isDebugEnabled())
log.debug("load default configuration: ");
if(choosenList == null)
choosenList = new ListConfigurationDAO().getDefaultListConfiguration(type, user);
else
choosenList = new ListConfigurationDAO().getById(choosenList.getId());
if(choosenList != null)
form.setListId(choosenList.getId());
}
if(choosenList != null)
panel.setAttribute("choosenList", choosenList);
// query database
Table table = (Table)panel.getAttribute(TABLE_KEY);
if(table == null) {
Integer[] columns = null;
if(choosenList != null)
columns = choosenList.getColumns();
table = TableFactory.getInstance().createTable(type.getName(), user, columns);
table.getPage().setStep(conf.getIntValue(UserConfiguration.Key.LIST_NUMBER_ROWS));
panel.setAttribute(TABLE_KEY, table);
}