Author: julien(a)jboss.com
Date: 2007-03-15 09:05:28 -0400 (Thu, 15 Mar 2007)
New Revision: 6681
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPage.xhtml
Log:
added proper page name validation logic
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java 2007-03-15
12:51:47 UTC (rev 6680)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/actions/AddPageAction.java 2007-03-15
13:05:28 UTC (rev 6681)
@@ -29,7 +29,10 @@
import org.jboss.portal.security.spi.provider.DomainConfigurator;
import org.jboss.portal.security.RoleSecurityBinding;
import org.jboss.portal.security.SecurityConstants;
+import org.apache.log4j.Logger;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
import java.util.Set;
import java.util.Collections;
@@ -41,65 +44,87 @@
{
/** . */
- public PageContainer pageContainer;
+ private static final Logger log = Logger.getLogger(AddPageAction.class);
/** . */
- public DomainConfigurator domainConfigurator;
+ private static final String ERROR_DUPE_NAME = "Duplicate Page name found on this
portal!";
/** . */
- public String pageName;
+ private static final String ERROR_EMPTY_NAME = "Page name cannot be
blank!";
/** . */
- public Listener listener;
+ private static final String ERROR_NO_NAME = "Page name not specified!";
/** . */
-// private static final String ERROR_DUPE_NAME = "Duplicate Page name found on
this portal!";
+ private static final String ERROR_INTERNAL_ERROR = "An internal error
happened!";
- /** . */
-// private static final String ERROR_EMPTY_NAME = "Page name cannot be
blank!";
+ /** The page container that will create the child. */
+ public PageContainer pageContainer;
- /*
- * Checks for duplicate page names on the portal instance. Blank page names are not
allowed and are controlled by the
- * required attribute in the presentation page.
- */
-// public void validatePageName(FacesContext context, UIComponent toValidate, Object
value)
-// {
-// String pageName = (String)value;
-//
-// // check for empty string
-// if (pageName.startsWith(" "))
-// {
-// FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
ERROR_EMPTY_NAME, ERROR_EMPTY_NAME);
-// throw new ValidatorException(message);
-// }
-//
-// // Check for duplicate child name
-// if (pageContainer.getChild(pageName) != null)
-// {
-// FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
ERROR_DUPE_NAME, ERROR_DUPE_NAME);
-// throw new ValidatorException(message);
-// }
-// }
+ /** The domain configurator for security. */
+ public DomainConfigurator domainConfigurator;
+ /** The page name to create. */
+ public String pageName;
+
+ /** An optional listener. */
+ public Listener listener;
+
+ /** The message id when an error happens. */
+ public String messageTarget;
+
public void execute()
{
- try
+ FacesMessage message = null;
+
+ //
+ if (pageName == null)
{
- Page page = pageContainer.createPage(pageName);
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_NO_NAME,
ERROR_NO_NAME);
+ }
+ else
+ {
+ pageName = pageName.trim();
//
- Set constraints = Collections.singleton(new
RoleSecurityBinding(PortalObjectPermission.VIEW_RECURSIVE_ACTION,
SecurityConstants.UNCHECKED_ROLE_NAME));
-
domainConfigurator.setSecurityBindings(page.getId().toString(PortalObjectId.CANONICAL_FORMAT),
constraints);
+ if (pageName.length() == 0)
+ {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_EMPTY_NAME,
ERROR_EMPTY_NAME);
+ }
+ else if (pageContainer.getChild(pageName) != null)
+ {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_DUPE_NAME,
ERROR_DUPE_NAME);
+ }
+ }
- //
- if (listener != null)
+ //
+ if (message == null)
+ {
+ try
{
- listener.pageCreated(page);
+ Page page = pageContainer.createPage(pageName);
+
+ //
+ Set constraints = Collections.singleton(new
RoleSecurityBinding(PortalObjectPermission.VIEW_RECURSIVE_ACTION,
SecurityConstants.UNCHECKED_ROLE_NAME));
+
domainConfigurator.setSecurityBindings(page.getId().toString(PortalObjectId.CANONICAL_FORMAT),
constraints);
+
+ //
+ if (listener != null)
+ {
+ listener.pageCreated(page);
+ }
}
+ catch (Exception e)
+ {
+ log.error("An error happened during page creation", e);
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR, ERROR_INTERNAL_ERROR,
ERROR_INTERNAL_ERROR);
+ }
}
- catch (Exception e)
+
+ //
+ if (message != null && messageTarget != null)
{
- e.printStackTrace();
+ FacesContext.getCurrentInstance().addMessage(messageTarget, message);
}
}
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2007-03-15
12:51:47 UTC (rev 6680)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2007-03-15
13:05:28 UTC (rev 6681)
@@ -97,6 +97,10 @@
<property-name>domainConfigurator</property-name>
<value>#{applicationScope.AuthorizationDomainRegistry.portalobject.configurator}</value>
</managed-property>
+ <managed-property>
+ <property-name>messageTarget</property-name>
+ <value>addPageForm:pageName</value>
+ </managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>themePropertyAction</managed-bean-name>
@@ -250,6 +254,10 @@
<value>#{applicationScope.AuthorizationDomainRegistry.portalobject.configurator}</value>
</managed-property>
<managed-property>
+ <property-name>messageTarget</property-name>
+ <value>error</value>
+ </managed-property>
+ <managed-property>
<property-name>listener</property-name>
<value>#{sessionScope.dashboard}</value>
</managed-property>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPage.xhtml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPage.xhtml 2007-03-15
12:51:47 UTC (rev 6680)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPage.xhtml 2007-03-15
13:05:28 UTC (rev 6681)
@@ -12,10 +12,10 @@
<div style="padding:1em 0 0 0">
<div class="portlet-font">Create a nested page:</div>
<div style="padding:1em 0 1em 0">
- <h:form>
- <h:inputText id="name"
value="#{addPageAction.pageName}"
styleClass="portlet-form-input-field" required="true"/>
+ <h:form id="addPageForm">
+ <h:inputText id="pageName"
value="#{addPageAction.pageName}"
styleClass="portlet-form-input-field" required="true"/>
<h:commandButton action="#{addPageAction.execute}"
value="Add" styleClass="portlet-form-button"/>
- <h:message for="name"
errorClass="portlet-msg-error"/>
+ <h:message for="pageName"
errorClass="portlet-msg-error"/>
</h:form>
</div>
</div>