Revision: 365
Author:   tfenne
Date:     2006-08-09 19:20:30 -0700 (Wed, 09 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/stripes/?rev=365&view=rev

Log Message:
-----------
Implementation of STS-233: Event Handler calling using single hidden input (as 
a last resort)

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
    trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java
    trunk/tests/src/net/sourceforge/stripes/controller/BasicResolverTests.java
Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2006-08-10 01:44:05 UTC (rev 364)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2006-08-10 02:20:30 UTC (rev 365)
@@ -362,19 +362,25 @@
 
 
     /**
-     * Searched for a parameter in the request whose name matches one of the 
named events handled
+     * <p>Searched for a parameter in the request whose name matches one of 
the named events handled
      * by the ActionBean.  For example, if the ActionBean can handle events 
foo and bar, this
      * method will scan the request for foo=somevalue and bar=somevalue.  If 
it find a request
      * paremeter with a matching name it will return that name.  If there are 
multiple matching
-     * names, the result of this method cannot be guaranteed.
+     * names, the result of this method cannot be guaranteed.</p>
      *
+     * <p>If the event name cannot be determined through the parameter names, 
two alternative
+     * strategies are employed. First if there is extra path information 
beyond the URL binding
+     * of the ActionBean, it is checked to see if it matches an event name.  
If that doesn't work,
+     * the value of a 'special' request parameter ([EMAIL PROTECTED] 
StripesConstants.URL_KEY_EVENT_NAME})
+     * is checked to see if contains a single value matching an event name.</p>
+     *
      * @param bean the ActionBean type bound to the request
      * @param context the ActionBeanContect for the current request
      * @return String the name of the event submitted, or null if none can be 
found
      */
     public String getEventName(Class<? extends ActionBean> bean, 
ActionBeanContext context) {
         Map<String,Method> mappings = this.eventMappings.get(bean);
-        Map parameterMap = context.getRequest().getParameterMap();
+        Map<String,String[]> parameterMap = 
context.getRequest().getParameterMap();
 
         // First try the traditional checking based on request parameters
         for (String event : mappings.keySet()) {
@@ -394,6 +400,12 @@
             }
         }
 
+        // Lastly if we still haven't picked an event, look for the special 
parameter
+        String[] name = parameterMap.get(StripesConstants.URL_KEY_EVENT_NAME);
+        if (name != null && name.length == 1 && mappings.containsKey(name[0])) 
{
+            return name[0];
+        }
+
         return null;
     }
 

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java  
2006-08-10 01:44:05 UTC (rev 364)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/StripesConstants.java  
2006-08-10 02:20:30 UTC (rev 365)
@@ -33,6 +33,12 @@
     String URL_KEY_FIELDS_PRESENT = "__fp";
 
     /**
+     * The name of a URL parameter that is used as a last resort to attempt to 
determine
+     * the name of the event that is being fired by the browser.
+     */
+    String URL_KEY_EVENT_NAME = "_eventName";
+
+    /**
      * The name under which the ActionBean for a request is stored as a 
request attribute before
      * forwarding to the JSP.
      */

Modified: 
trunk/tests/src/net/sourceforge/stripes/controller/BasicResolverTests.java
===================================================================
--- trunk/tests/src/net/sourceforge/stripes/controller/BasicResolverTests.java  
2006-08-10 01:44:05 UTC (rev 364)
+++ trunk/tests/src/net/sourceforge/stripes/controller/BasicResolverTests.java  
2006-08-10 02:20:30 UTC (rev 365)
@@ -77,4 +77,15 @@
         BasicResolverTests bean = trip.getActionBean( getClass() );
         Assert.assertEquals(bean.getNumber(), 2);
     }
+
+    @Test(groups="fast")
+    public void testEventNameParameterResolution() throws Exception {
+        MockRoundtrip trip = new 
MockRoundtrip(StripesTestFixture.getServletContext(), getClass());
+        trip.addParameter(StripesConstants.URL_KEY_EVENT_NAME, "two");
+        trip.execute();
+
+        BasicResolverTests bean = trip.getActionBean( getClass() );
+        Assert.assertEquals(bean.getNumber(), 2);
+        Assert.assertEquals(bean.getContext().getEventName(), "two");
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to