UIPageSelector pageSelector = uiPageNodeForm.getChild(UIPageSelector.class);
if (pageSelector.getPage() == null) {
pageSelector.setValue(null);
} else {
PageContext pageContext = pageSelector.getPage();
DataStorage storage = uiPageNodeForm.getApplicationComponent(DataStorage.class);
PageService pageService = uiPageNodeForm.getApplicationComponent(PageService.class);
if (pageService.loadPage(pageContext.getKey()) == null) {
pageService.savePage(pageContext);
//
Page page = new Page();
page.setOwnerType(pageContext.getKey().getSite().getTypeName());
page.setOwnerId(pageContext.getKey().getSite().getName());
page.setName(pageContext.getKey().getName());
String title = pageContext.getState().getDisplayName();
String[] accessPermission = pageContext.getState().getAccessPermissions() == null ? null : pageContext
.getState().getAccessPermissions()
.toArray(new String[pageContext.getState().getAccessPermissions().size()]);
if (title == null || title.trim().length() < 1) {
title = page.getName();
}
page.setTitle(title);
page.setShowMaxWindow(false);
page.setAccessPermissions(accessPermission);
page.setEditPermission(pageContext.getState().getEditPermission());
page.setModifiable(true);
if (page.getChildren() == null) {
page.setChildren(new ArrayList<ModelObject>());
}