}
public static class CreatePageActionListener extends EventListener<UIPageNodeForm> {
public void execute(Event<UIPageNodeForm> event) throws Exception {
UIPageNodeForm uiForm = event.getSource();
UIPageSelector pageSelector = uiForm.findFirstComponentOfType(UIPageSelector.class);
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 (SiteType.PORTAL.equals(uiForm.getOwnerType())) {
UIPortal uiPortal = Util.getUIPortal();
accessPermission = uiPortal.getAccessPermissions();
editPermission = uiPortal.getEditPermission();
}
UIFormStringInput uiPageName = uiInputSet.getChildById("pageName");
UIFormStringInput uiPageTitle = uiInputSet.getChildById("pageTitle");
PageState pageState = new PageState(uiPageTitle.getValue(), null, false, null,
accessPermission != null ? Arrays.asList(accessPermission) : null, editPermission);
// check page is exist
PageKey pageKey = PageKey.parse(uiForm.getOwnerType().getName() + "::" + ownerId + "::" + uiPageName.getValue());
PageService pageService = uiForm.getApplicationComponent(PageService.class);
PageContext existPage = pageService.loadPage(pageKey);
if (existPage != null) {
uiPortalApp.addMessage(new ApplicationMessage("UIPageForm.msg.sameName", null));
return;
}
pageSelector.setPage(new PageContext(pageKey, pageState));
event.getRequestContext().addUIComponentToUpdateByAjax(pageSelector);
}