{
UIPageNodeForm uiForm = event.getSource();
UIPageSelector2 pageSelector = uiForm.findFirstComponentOfType(UIPageSelector2.class);
PortalRequestContext pcontext = Util.getPortalRequestContext();
UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
UIFormInputSet uiInputSet = pageSelector.getChild(UIFormInputSet.class);
List<UIComponent> children = uiInputSet.getChildren();
/*********************************************************************/
for (UIComponent uiChild : children)
{
if (uiChild instanceof UIFormInputBase)
{
UIFormInputBase uiInput = (UIFormInputBase)uiChild;
if (!uiInput.isValid())
continue;
List<Validator> validators = uiInput.getValidators();
if (validators == null)
continue;
try
{
for (Validator validator : validators)
validator.validate(uiInput);
}
catch (MessageException ex)
{
uiPortalApp.addMessage(ex.getDetailMessage());
return;
}
catch (Exception ex)
{
//TODO: This is a critical exception and should be handle in the UIApplication
uiPortalApp.addMessage(new ApplicationMessage(ex.getMessage(), null));
return;
}
}
}
UserACL userACL = uiForm.getApplicationComponent(UserACL.class);
String ownerId = uiForm.getOwner();
String[] accessPermission = new String[1];
accessPermission[0] = "*:" + ownerId;
String editPermission = userACL.getMakableMT() + ":" + ownerId;
if (PortalConfig.PORTAL_TYPE.equals(uiForm.getOwnerType()))
{
UIPortal uiPortal = Util.getUIPortal();
accessPermission = uiPortal.getAccessPermissions();
editPermission = uiPortal.getEditPermission();
}
UIFormStringInput uiPageName = uiInputSet.getChildById("pageName");
UIFormStringInput uiPageTitle = uiInputSet.getChildById("pageTitle");
Page page = new Page();
page.setOwnerType(uiForm.getOwnerType());
page.setOwnerId(ownerId);
page.setName(uiPageName.getValue());
String title = uiPageTitle.getValue();;
if (title == null || title.trim().length() < 1)
title = page.getName();
page.setTitle(title);
page.setShowMaxWindow(false);
page.setAccessPermissions(accessPermission);
page.setEditPermission(editPermission);
userACL.hasPermission(page);
page.setModifiable(true);
if (page.getChildren() == null)
page.setChildren(new ArrayList<ModelObject>());
// check page is exist
DataStorage dataService = uiForm.getApplicationComponent(DataStorage.class);
Page existPage = dataService.getPage(page.getPageId());
if (existPage != null)
{
uiPortalApp.addMessage(new ApplicationMessage("UIPageForm.msg.sameName", null));
pcontext.addUIComponentToUpdateByAjax(uiPortalApp.getUIPopupMessages());
return;
}
// save page to database
dataService.create(page);