Author: rich
Date: Mon Jun 13 22:02:13 2005
New Revision: 190554

URL: http://svn.apache.org/viewcvs?rev=190554&view=rev
Log:
Fix for http://issues.apache.org/jira/browse/BEEHIVE-812 : Cannot provide an 
initial value for an action that accepts an interface as its form bean

Also added a test of posting data directly into an XmlBean.  This functionality 
wasn't broken; the test was just conspicuously missing.

tests: bvt in netui (WinXP)
BB: self (linux)


Added:
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf
   (with props)
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp
   (with props)
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf
   (with props)
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp
   (with props)
    
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp
   (with props)
Modified:
    
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java

Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java?rev=190554&r1=190553&r2=190554&view=diff
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowUtils.java
 Mon Jun 13 22:02:13 2005
@@ -532,21 +532,48 @@
             //
             // Get the names of *all* form beans of the desired type, and 
blast out this instance under all those names.
             //
-            List/*< String >*/ formNames = getFormNamesFromModuleConfig( 
formClass.getName(), moduleConfig );
+            List formNames = getFormNamesFromModuleConfig( 
formClass.getName(), moduleConfig );
+            List additionalFormNames = null;
             
-            if ( formNames == null )
+            //
+            // formNames is a statically-scoped list.  Below, we create a 
dynamic list of form names that correspond
+            // to *implemented interfaces* of the given form bean class.
+            //
+            Class[] interfaces = formClass.getInterfaces();
+            for ( int i = 0; i < interfaces.length; i++ )
+            {
+                Class formInterface = interfaces[i];
+                List toAdd = getFormNamesFromModuleConfig( 
formInterface.getName(), moduleConfig );
+                if ( toAdd != null )
+                {
+                    if ( additionalFormNames == null ) additionalFormNames = 
new ArrayList();
+                    additionalFormNames.addAll( toAdd );
+                }
+            }
+            
+            if ( formNames == null && additionalFormNames == null )
             {
                 String formName = generateFormBeanName( formClass, request );
                 InternalUtils.setFormInScope( formName, form, mapping, 
request, overwrite );
             }
             else
             {
-                assert formNames.size() > 0;    // 
getFormNamesFromModuleConfig returns null or a nonempty list
+                if ( formNames != null )
+                {
+                    for ( Iterator i = formNames.iterator(); i.hasNext(); )  
+                    {
+                        String formName = ( String ) i.next();
+                        InternalUtils.setFormInScope( formName, form, mapping, 
request, overwrite );
+                    }
+                }
                 
-                for ( Iterator ii = formNames.iterator(); ii.hasNext(); )  
+                if ( additionalFormNames != null )
                 {
-                    String formName = ( String ) ii.next();
-                    InternalUtils.setFormInScope( formName, form, mapping, 
request, overwrite );
+                    for ( Iterator i = additionalFormNames.iterator(); 
i.hasNext(); )  
+                    {
+                        String formName = ( String ) i.next();
+                        InternalUtils.setFormInScope( formName, form, mapping, 
request, overwrite );
+                    }
                 }
             }
         }

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf?rev=190554&view=auto
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf
 (added)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf
 Mon Jun 13 22:02:13 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package miniTests.initFormBeanInterface;
+
+import org.apache.beehive.netui.pageflow.*;
+import org.apache.beehive.netui.pageflow.annotations.*;
+import java.io.Serializable;
+
[EMAIL PROTECTED]()
+public class Controller extends PageFlowController
+{
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="index", path="index.jsp")
+        }
+    )
+    public Forward begin()
+    {
+        MyForm bean = new MyForm();
+        bean.setFoo( "got it" );
+        return new Forward( "index", bean );
+    }
+
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(name="index", path="index.jsp")
+        }
+    )
+    public Forward submit( MyFormInterface form )
+    {
+        return new Forward( "index" );
+    }
+
+    public static class MyForm
+        implements MyFormInterface, Serializable
+    {
+        private String _foo;
+
+        public String getFoo()
+        {
+            return _foo;
+        }
+
+        public void setFoo( String foo )
+        {
+            _foo = foo;
+        }
+    }
+
+    public interface MyFormInterface
+    {
+        public String getFoo();
+        public void setFoo( String foo );
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/Controller.jpf
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp?rev=190554&view=auto
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp
 (added)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp
 Mon Jun 13 22:02:13 2005
@@ -0,0 +1,27 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" 
uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" 
uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+
+
+<netui:html>
+    <head>
+        <netui:base/>
+    </head>
+    <netui:body>
+        <h3>${pageFlow.URI}</h3>
+
+        This test verifies that we can initialize the form bean on a JSP even 
when the destination
+        action accepts an <i>interface</i> as its form bean argument.  The 
previous action passes a
+        concrete implementation of that interface on the Forward to this page.
+        <br/>
+        <br/>
+
+        <netui:form action="submit">
+            foo: <netui:textBox dataSource="actionForm.foo"/><netui:error 
key="foo"/>
+        </netui:form>
+    </netui:body>
+</netui:html>
+
+  
+

Propchange: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/initFormBeanInterface/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf?rev=190554&view=auto
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf
 (added)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf
 Mon Jun 13 22:02:13 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package miniTests.postToXmlBean;
+
+import org.apache.beehive.netui.pageflow.*;
+import org.apache.beehive.netui.pageflow.annotations.*;
+import org.openuri.customerPortfolio.Stock;
+
[EMAIL PROTECTED](
+    simpleActions={
+        @Jpf.SimpleAction(name="begin", path="index.jsp")
+    }
+)
+public class Controller extends PageFlowController
+{
+    @Jpf.Action(
+        forwards={
+            @Jpf.Forward(
+                name="success",
+                path="success.jsp",
+                actionOutputs={
+                    @Jpf.ActionOutput(name="stock", type=Stock.class, 
required=true)
+                }
+            )
+        },
+        validatableProperties={
+            @Jpf.ValidatableProperty(
+                propertyName="symbol",
+                displayName="The symbol",
+                [EMAIL PROTECTED](),
+                [EMAIL PROTECTED](
+                    regex="[A-Z][A-Z][A-Z][A-Z]",
+                    message="The symbol must be exacly four uppercase 
characters."
+                )
+            ),
+            @Jpf.ValidatableProperty(
+                propertyName="name",
+                displayName="The name",
+                [EMAIL PROTECTED]()
+            ),
+            @Jpf.ValidatableProperty(
+                propertyName="price",
+                displayName="The price",
+                [EMAIL PROTECTED](minFloat=0.01, maxFloat=100000.00)
+            )
+        },
+        [EMAIL PROTECTED](name="failure", path="index.jsp")
+    )
+    public Forward submit( Stock stock )
+    {
+        return new Forward( "success", "stock", stock );
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/Controller.jpf
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp?rev=190554&view=auto
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp
 (added)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp
 Mon Jun 13 22:02:13 2005
@@ -0,0 +1,41 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" 
uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" 
uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+
+
+<netui:html>
+    <head>
+        <netui:base/>
+    </head>
+    <netui:body>
+        <h3>${pageFlow.URI}</h3>
+
+        This test confirms that we can post data directly into an XmlBean (and 
also that we can run
+        validation rules on XmlBean properties).
+        <br/>
+        <br/>
+
+        <netui:form action="submit">
+            <table>
+                <tr>
+                    <td>symbol:</td>
+                    <td><netui:textBox 
dataSource="actionForm.symbol"/><netui:error key="symbol"/></td>
+                </tr>
+                <tr>
+                    <td>name:</td>
+                    <td><netui:textBox 
dataSource="actionForm.name"/><netui:error key="name"/></td>
+                </tr>
+                <tr>
+                    <td>price:</td>
+                    <td><netui:textBox 
dataSource="actionForm.price"/><netui:error key="price"/></td>
+                </tr>
+            </table>
+            <br/>
+            <netui:button value="submit"/>
+        </netui:form>
+    </netui:body>
+</netui:html>
+
+  
+

Propchange: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/index.jsp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp?rev=190554&view=auto
==============================================================================
--- 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp
 (added)
+++ 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp
 Mon Jun 13 22:02:13 2005
@@ -0,0 +1,36 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data" 
uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template" 
uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+
+
+<netui:html>
+    <head>
+        <netui:base/>
+    </head>
+    <netui:body>
+        <h3>${pageFlow.URI}</h3>
+
+        Success.  The data submitted was:
+        <table>
+            <tr>
+                <td>symbol:</td>
+                <td><b>${pageInput.stock.symbol}</b></td>
+            </tr>
+            <tr>
+                <td>name:</td>
+                <td><b>${pageInput.stock.name}</b></td>
+            </tr>
+            <tr>
+                <td>price:</td>
+                <td><b>${pageInput.stock.price}</b></td>
+            </tr>
+        </table>
+
+        <br/>
+        <netui:anchor action="begin">start over</netui:anchor>
+    </netui:body>
+</netui:html>
+
+
+

Propchange: 
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/miniTests/postToXmlBean/success.jsp
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to