Author: jonesde
Date: Wed Mar  4 10:27:52 2009
New Revision: 749959

URL: http://svn.apache.org/viewvc?rev=749959&view=rev
Log:
Simple implementation of feature discussed on the mailing list to facilitate 
getting back to a view after some generic action, like schanging the locale 
which this commit has use the new feature as a test case; I'm not sure I like 
this approach, will send message to dev list about it

Modified:
    ofbiz/trunk/applications/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
    ofbiz/trunk/framework/common/webcommon/WEB-INF/common-controller.xml
    ofbiz/trunk/framework/common/webcommon/includes/listLocales.ftl
    ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java

Modified: 
ofbiz/trunk/applications/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/ecommerce/webapp/ecommerce/WEB-INF/controller.xml?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- ofbiz/trunk/applications/ecommerce/webapp/ecommerce/WEB-INF/controller.xml 
(original)
+++ ofbiz/trunk/applications/ecommerce/webapp/ecommerce/WEB-INF/controller.xml 
Wed Mar  4 10:27:52 2009
@@ -140,7 +140,7 @@
     <request-map uri="setSessionLocale">
         <security https="false" auth="false"/>
         <event type="java" path="org.ofbiz.common.CommonEvents" 
invoke="setSessionLocale"/>
-        <response name="success" type="view" value="main"/>
+        <response name="success" type="view-last" value="main"/>
         <response name="error" type="view" value="main"/>
     </request-map>
     

Modified: ofbiz/trunk/framework/common/webcommon/WEB-INF/common-controller.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/WEB-INF/common-controller.xml?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/webcommon/WEB-INF/common-controller.xml 
(original)
+++ ofbiz/trunk/framework/common/webcommon/WEB-INF/common-controller.xml Wed 
Mar  4 10:27:52 2009
@@ -88,26 +88,20 @@
     </request-map>
 
     <!-- Common Mappings used for locales and timezones -->
+    <request-map uri="LookupLocales"><security https="true" 
auth="false"/><response name="success" type="view" value="LookupLocales" 
save-last-view="true"/></request-map>
     <request-map uri="setSessionLocale">
         <security https="true" auth="false"/>
         <event type="java" path="org.ofbiz.common.CommonEvents" 
invoke="setSessionLocale"/>
-        <response name="success" type="request" value="main"/>
+        <response name="success" type="view-last" value="main"/>
         <response name="error" type="request" value="main"/>
     </request-map>
+    <request-map uri="LookupTimezones"><security https="true" 
auth="false"/><response name="success" type="view" 
value="LookupTimezones"/></request-map>
     <request-map uri="setSessionTimeZone">
         <security https="true" auth="false"/>
         <event type="java" path="org.ofbiz.common.CommonEvents" 
invoke="setSessionTimeZone"/>
         <response name="success" type="request" value="main"/>
         <response name="error" type="request" value="main"/>
     </request-map>
-    <request-map uri="LookupLocales">
-        <security https="true" auth="false" />
-        <response name="success" type="view" value="LookupLocales" />
-    </request-map>
-    <request-map uri="LookupTimezones">
-        <security https="true" auth="false" />
-        <response name="success" type="view" value="LookupTimezones" />
-    </request-map>
 
     <!-- User preference mapping -->
     <request-map uri="setUserPreference">

Modified: ofbiz/trunk/framework/common/webcommon/includes/listLocales.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/includes/listLocales.ftl?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/webcommon/includes/listLocales.ftl (original)
+++ ofbiz/trunk/framework/common/webcommon/includes/listLocales.ftl Wed Mar  4 
10:27:52 2009
@@ -51,7 +51,7 @@
         </#if>
         <tr <#if altRow>class="alternate-row"</#if>>
             <td lang="${langAttr}" dir="${langDir}">
-                <a 
href="<@ofbizUrl>setSessionLocale</@ofbizUrl>?newLocale=${availableLocale.toString()}">${availableLocale.getDisplayName(availableLocale)}</a>
+                <a 
href="<@ofbizUrl>setSessionLocale</@ofbizUrl>?newLocale=${availableLocale.toString()}">${availableLocale.getDisplayName(availableLocale)}
 [${availableLocale.toString()}]</a>
             </td>
         </tr>
     </#list>

Modified: ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original)
+++ ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Wed Mar  4 10:27:52 2009
@@ -217,9 +217,9 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.event">
-        <xs:attribute type="xs:string" name="type" use="required"/>
-        <xs:attribute type="xs:string" name="path"/>
-        <xs:attribute type="xs:string" name="invoke"/>
+        <xs:attribute name="type" type="xs:string" use="required"/>
+        <xs:attribute name="path" type="xs:string"/>
+        <xs:attribute name="invoke" type="xs:string"/>
         <xs:attribute name="global-transaction" default="true">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
@@ -238,12 +238,13 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.response">
-        <xs:attribute type="xs:string" name="name" use="required"/>
+        <xs:attribute name="name" type="xs:string" use="required"/>
         <xs:attribute name="type" use="required">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
                     <xs:enumeration value="none"/>
                     <xs:enumeration value="view"/>
+                    <xs:enumeration 
value="view-last"><xs:annotation><xs:documentation>Will use the view from the 
last request unless there is a saved from some previous request (using the 
save-last-view attribute).</xs:documentation></xs:annotation></xs:enumeration>
                     <xs:enumeration value="request"/>
                     <xs:enumeration value="request-redirect"/>
                     <xs:enumeration value="request-redirect-noparam"/>
@@ -251,7 +252,16 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="value"/>
+        <xs:attribute name="value" type="xs:string"/>
+        <xs:attribute name="save-last-view" default="false">
+            <xs:annotation><xs:documentation>Saves the last (previous) 
request's view for future use, generally with the view-last type of 
response.</xs:documentation></xs:annotation>
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="true"/>
+                    <xs:enumeration value="false"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="redirect-parameter">
         <xs:annotation><xs:documentation>Adds a parameter with the given name 
to the redirect. Finds value in a request attribute if exists, or a request 
parameter if no attribute is found.</xs:documentation></xs:annotation>

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
Wed Mar  4 10:27:52 2009
@@ -425,12 +425,14 @@
         public String name;
         public String type;
         public String value;
+        public boolean saveLastView = false;
         public Map<String, String> redirectParameterMap = 
FastMap.newInstance();
         
         public RequestResponse(Element responseElement) {
             this.name = responseElement.getAttribute("name");
             this.type = responseElement.getAttribute("type");
             this.value = responseElement.getAttribute("value");
+            this.saveLastView = 
"true".equals(responseElement.getAttribute("save-last-view"));
             for (Element redirectParameterElement: 
UtilXml.childElementList(responseElement, "redirect-parameter")) {
                 String from = redirectParameterElement.getAttribute("from");
                 if (UtilValidate.isEmpty(from)) from = 
redirectParameterElement.getAttribute("name");

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=749959&r1=749958&r2=749959&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
Wed Mar  4 10:27:52 2009
@@ -448,7 +448,14 @@
         
         if (Debug.verboseOn()) Debug.logVerbose("[Event Response Selected]  
type=" + nextRequestResponse.type + ", value=" + nextRequestResponse.value + ", 
sessionId=" + UtilHttp.getSessionId(request), module);
 
-        // Handle the responses - chains/views
+        // ========== Handle the responses - chains/views ==========
+        
+        // if the request has the save-last-view attribute set, save it now 
before the view can be rendered or other chain done so that the _LAST* session 
attributes will represent the previous request
+        if (nextRequestResponse.saveLastView) {
+            session.setAttribute("_SAVED_VIEW_NAME_", 
session.getAttribute("_LAST_VIEW_NAME_"));
+            session.setAttribute("_SAVED_VIEW_URL_PARAMS_", 
session.getAttribute("_LAST_VIEW_URL_PARAMS_"));
+        }
+        
         if (nextRequestResponse != null && 
"request".equals(nextRequestResponse.type)) {
             // chained request
             Debug.logInfo("[RequestHandler.doRequest]: Response is a chained 
request." + " sessionId=" + UtilHttp.getSessionId(request), module);
@@ -488,6 +495,28 @@
                 // check for an override view, only used if "success" = 
eventReturn
                 String viewName = (UtilValidate.isNotEmpty(overrideViewUri) && 
(eventReturn == null || "success".equals(eventReturn))) ? overrideViewUri : 
nextRequestResponse.value;
                 renderView(viewName, requestMap.securityExternalView, request, 
response);
+            } else if ("view-last".equals(nextRequestResponse.type)) {
+                if (Debug.verboseOn()) 
Debug.logVerbose("[RequestHandler.doRequest]: Response is a view." + " 
sessionId=" + UtilHttp.getSessionId(request), module);
+                
+                // check for an override view, only used if "success" = 
eventReturn
+                String viewName = (UtilValidate.isNotEmpty(overrideViewUri) && 
(eventReturn == null || "success".equals(eventReturn))) ? overrideViewUri : 
nextRequestResponse.value;
+                
+                // as a further override, look for the _SAVED and then _LAST 
session attributes
+                Map<String, Object> urlParams = null;
+                if (session.getAttribute("_SAVED_VIEW_NAME_") != null) {
+                    viewName = (String) 
session.getAttribute("_SAVED_VIEW_NAME_");
+                    urlParams = (Map<String, Object>) 
session.getAttribute("_SAVED_VIEW_URL_PARAMS_");
+                } else if (session.getAttribute("_LAST_VIEW_NAME_") != null) {
+                    viewName = (String) 
session.getAttribute("_LAST_VIEW_NAME_");
+                    urlParams = (Map<String, Object>) 
session.getAttribute("_LAST_VIEW_URL_PARAMS_");
+                }
+                if (urlParams != null) {
+                    for (Map.Entry<String, Object> urlParamEntry: 
urlParams.entrySet()) {
+                        request.setAttribute(urlParamEntry.getKey(), 
urlParamEntry.getValue());
+                    }
+                }
+                
+                renderView(viewName, requestMap.securityExternalView, request, 
response);
             } else if ("none".equals(nextRequestResponse.type)) {
                 // no view to render (meaning the return was processed by the 
event)
                 if (Debug.verboseOn()) 
Debug.logVerbose("[RequestHandler.doRequest]: Response is handled by the 
event." + " sessionId=" + UtilHttp.getSessionId(request), module);
@@ -613,8 +642,13 @@
 
         if (Debug.verboseOn()) Debug.logVerbose("[Getting View Map]: " + view 
+ " sessionId=" + UtilHttp.getSessionId(req), module);
 
-        // before mapping the view, set a session attribute so we know where 
we are
+        // before mapping the view, set a request attribute so we know where 
we are
         req.setAttribute("_CURRENT_VIEW_", view);
+        
+        // save the view in the session for the last view, plus the URL 
parameters Map; note that this is saved after the request/view processing has 
finished so when those run they will get the value from the previous request
+        Map<String, Object> queryStringParamMap = 
UtilHttp.getQueryStringOnlyParameterMap(req);
+        req.getSession().setAttribute("_LAST_VIEW_NAME_", view);
+        req.getSession().setAttribute("_LAST_VIEW_URL_PARAMS_", 
queryStringParamMap);
 
         ConfigXMLReader.ViewMap viewMap = (view == null ? null : 
getControllerConfig().viewMapMap.get(view));
         if (viewMap == null) {


Reply via email to