Author: craigmcc
Date: Mon Dec 11 22:52:47 2006
New Revision: 486047

URL: http://svn.apache.org/viewvc?view=rev&rev=486047
Log:
Restore the ability to override the default prefix for triggering the start of
a dialog via a navigation outcome.  While we are at it, document this, and the
previously added support for a data class that implements DialogContextListener
in the web site.

SHALE-355

Modified:
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogNavigationHandler.java
    shale/framework/trunk/shale-dialog/src/site/xdoc/index.xml

Modified: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java?view=diff&rev=486047&r1=486046&r2=486047
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
 Mon Dec 11 22:52:47 2006
@@ -76,10 +76,19 @@
 
 
     /**
-     * <p>Prefix on a logical outcome that indicates a new dialog instance
+     * <p>Default prefix on a logical outcome that indicates a new dialog 
instance
      * should be initiated.</p>
      */
     public static final String DIALOG_PREFIX = "dialog:";
+
+
+    /**
+     * <p>Context initialization attribute that specifies an override for the
+     * default prefix on a logical outcome that indicates a new dialog instance
+     * should be initiated.</p>
+     */
+    public static final String DIALOG_PREFIX_PARAM =
+            "org.apache.shale.dialog.DIALOG_PREFIX";
 
 
     /**

Modified: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogNavigationHandler.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogNavigationHandler.java?view=diff&rev=486047&r1=486046&r2=486047
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogNavigationHandler.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogNavigationHandler.java
 Mon Dec 11 22:52:47 2006
@@ -17,6 +17,7 @@
 
 package org.apache.shale.dialog.faces;
 
+import java.util.Map;
 import javax.faces.application.NavigationHandler;
 import javax.faces.context.FacesContext;
 
@@ -81,7 +82,9 @@
      *     a [EMAIL PROTECTED] DialogContext} instance:
      *     <ul>
      *     <li>If the logical outcome begins with the prefix identified
-     *         by <code>Constants.DIALOG_PREFIX</code>, create and start
+     *         by the prefix specified by context init parameter
+     *         <code>Constants.DIALOG_PREFIX_PARAM</code> (with a default
+     *         value of <code>Constants.DIALOG_PREFIX</code>), create and start
      *         a new [EMAIL PROTECTED] DialogContext} instance for a logical 
name
      *         based on the remainder of the logical outcome after the
      *         prefix.</li>
@@ -109,18 +112,19 @@
 
         DialogContext dcontext = (DialogContext)
           
context.getExternalContext().getRequestMap().get(Constants.CONTEXT_BEAN);
+        String prefix = prefix(context);
         if (dcontext == null) {
-            if ((outcome != null) && 
outcome.startsWith(Constants.DIALOG_PREFIX)) {
+            if ((outcome != null) && outcome.startsWith(prefix)) {
                 // Create and start a new DialogContext instance
                 DialogContextManager manager = (DialogContextManager)
                   context.getApplication().getVariableResolver().
                   resolveVariable(context, Constants.MANAGER_BEAN);
                 dcontext =
-                  manager.create(context, 
outcome.substring(Constants.DIALOG_PREFIX.length()));
+                  manager.create(context, outcome.substring(prefix.length()));
                 dcontext.start(context);
                 if (log.isDebugEnabled()) {
                     log.debug("Starting dialog '"
-                              + 
outcome.substring(Constants.DIALOG_PREFIX.length())
+                              + outcome.substring(prefix.length())
                               + "' for FacesContext instance '"
                               + context + "' with navigation to viewId '"
                               + context.getViewRoot().getViewId() + "'");
@@ -141,6 +145,38 @@
                           + context.getViewRoot().getViewId() + "'");
             }
         }
+
+    }
+
+
+    // --------------------------------------------------------- Private 
Methods
+
+
+    /**
+     * <p>Cache the calculated value of the prefix that triggers starting
+     * a dialog.</p>
+     */
+    private String prefix = null;
+
+
+    /**
+     * <p>Return the prefix string that indicates a logical outcome that
+     * should trigger starting a dialog.  The default value can be overridden
+     * by an appropriate context initialization parameter.</p>
+     *
+     * @param context <code>FacesContext</code> for the current request
+     */
+    private String prefix(FacesContext context) {
+
+        if (prefix != null) {
+            return prefix;
+        }
+        prefix = context.getExternalContext().
+          getInitParameter(Constants.DIALOG_PREFIX_PARAM);
+        if (prefix == null) {
+            prefix = Constants.DIALOG_PREFIX;
+        }
+        return prefix;
 
     }
 

Modified: shale/framework/trunk/shale-dialog/src/site/xdoc/index.xml
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/site/xdoc/index.xml?view=diff&rev=486047&r1=486046&r2=486047
==============================================================================
--- shale/framework/trunk/shale-dialog/src/site/xdoc/index.xml (original)
+++ shale/framework/trunk/shale-dialog/src/site/xdoc/index.xml Mon Dec 11 
22:52:47 2006
@@ -263,6 +263,14 @@
         return a logical outcome string of <code>dialog:foo</code>, and a new
         <code>DialogContext</code> instance will be started for you.</p>
 
+        <p>In the example above, we used the default <code>dialog:</code> 
prefix
+        value to trigger starting a dialog.  You can also specify your own
+        prefix by setting a context init parameter whose name is defined by
+        the symbolic constant <code>Constants.DIALOG_PREFIX_PARAM</code>
+        (i.e. <code>org.apache.shale.dialog.DIALOG_PREFIX</code>).  By 
convention
+        this value should end with a ':' character to look like a namespace,
+        but this is <strong>not</strong> required.</p>
+
         <h5>Starting A DialogContext Programmatically</h5>
 
         <p>Under some circumstances, it may be preferable for your 
application's
@@ -353,6 +361,20 @@
 <source>
   &lt;h:inputText id="name" ... value="#{dialog.data.name}"/>
 </source>
+
+        <p>As an extra value-added feature, if the object you store as the
+        <code>data</code> property is of a class that implements the
+        <code>DialogContextListener</code> interface, your data object will
+        also be automatically registered to receive the corresponding events.
+        This can be useful (for example), when your application needs to know
+        when a particular "state" has been entered, or whether a transition
+        to a particular "state" came from some other particular "state".</p>
+
+        <p>If you intend to leverage this feature, you can optionally make your
+        data class extend <code>AbstractDialogContextListener</code> instead of
+        implementing the interface directly.  If you do this, you only need to
+        implement the event handling methods that you are interested in, rather
+        than all of them.</p>
 
         <h4>Stopping An Active DialogContext Instance</h4>
 


Reply via email to