UIPagePreview uiPagePreview = getChild(UIPagePreview.class);
UIPage uiPage = (UIPage)uiPagePreview.getUIComponent();
UIPortal uiPortal = Util.getUIPortal();
UIWizardPageSetInfo uiPageInfo = getChild(UIWizardPageSetInfo.class);
UIPageNodeSelector uiNodeSelector = uiPageInfo.getChild(UIPageNodeSelector.class);
PageNode selectedNode = uiNodeSelector.getSelectedPageNode();
PageNavigation pageNav = uiNodeSelector.getSelectedNavigation();
if (PortalConfig.USER_TYPE.equals(pageNav.getOwnerType()))
selectedNode = null;
Page page = (Page)PortalDataMapper.buildModelObject(uiPage);
PageNode pageNode = uiPageInfo.getPageNode();
pageNode.setPageReference(page.getPageId());
if (selectedNode != null)
{
List<PageNode> children = selectedNode.getChildren();
if (children == null)
{
children = new ArrayList<PageNode>();
}
children.add(pageNode);
selectedNode.setChildren((ArrayList<PageNode>)children);
}
else
{
pageNav.addNode(pageNode);
}
uiNodeSelector.selectPageNodeByUri(pageNode.getUri());
DataStorage dataService = getApplicationComponent(DataStorage.class);
dataService.create(page);
dataService.save(pageNav);
setNavigation(uiPortal.getNavigations(), uiNodeSelector.getSelectedNavigation());
PageNodeEvent<UIPortal> pnevent = new PageNodeEvent<UIPortal>(uiPortal, PageNodeEvent.CHANGE_PAGE_NODE, pageNode.getUri());
uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
}