You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/07/07 07:40:33 UTC

svn commit: r791709 - in /myfaces/core/branches/2_0_0: api/src/main/java/javax/faces/context/ impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/context/flash/ impl/src/main/java/org/apache/myfaces/context/servlet/...

Author: lu4242
Date: Tue Jul  7 05:40:32 2009
New Revision: 791709

URL: http://svn.apache.org/viewvc?rev=791709&view=rev
Log:
MYFACES-2266 Implement Flash object and EL resolver

Added:
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java   (with props)
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java   (with props)
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java   (with props)
    myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/
    myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java   (with props)
Modified:
    myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/Flash.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleImpl.java

Modified: myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/Flash.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/Flash.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/Flash.java (original)
+++ myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/context/Flash.java Tue Jul  7 05:40:32 2009
@@ -39,4 +39,8 @@
     public abstract void setKeepMessages(boolean newValue);
     
     public abstract void setRedirect(boolean newValue);
+    
+    public abstract void doPrePhaseActions(FacesContext context);
+    
+    public abstract void doPostPhaseActions(FacesContext context);
 }

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java Tue Jul  7 05:40:32 2009
@@ -91,7 +91,9 @@
                 ExternalContext externalContext = facesContext.getExternalContext();
                 ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
                 String redirectPath = viewHandler.getActionURL(facesContext, navigationCase.getToViewId());
-
+                
+                // JSF 2.0 Spec call Flash.setRedirect(true) to notify Flash scope and take proper actions
+                externalContext.getFlash().setRedirect(true);
                 try
                 {
                     externalContext.redirect(externalContext.encodeActionURL(redirectPath));

Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java?rev=791709&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java Tue Jul  7 05:40:32 2009
@@ -0,0 +1,671 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.context.flash;
+
+import java.math.BigInteger;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.Flash;
+import javax.faces.event.PhaseId;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * Implementation of Flash object
+ * 
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FlashImpl extends Flash
+{
+    /**
+     * Key on app map to keep current instance
+     */
+    static protected final String FLASH_INSTANCE = FlashImpl.class.getName()
+            + ".INSTANCE";
+
+    /**
+     * Key used to check if there is the current request will be or was redirected
+     */
+    static protected final String FLASH_REDIRECT = FlashImpl.class.getName()
+            + ".REDIRECT";
+    
+    /**
+     * Key used to check if this request should keep messages (like tomahawk sandbox RedirectTracker. 
+     * Used when post-redirect-get pattern is used)
+     */
+    static protected final String FLASH_KEEP_MESSAGES = FlashImpl.class.getName()
+            + ".KEEP_MESSAGES";
+
+    /**
+     * Session map prefix to flash maps
+     */
+    static protected final String FLASH_SCOPE_CACHE = FlashImpl.class.getName()
+            + ".SCOPE";
+
+    static protected final String FLASH_CURRENT_MAP_CACHE = FlashImpl.class.getName()
+            + ".CURRENTMAP.CACHE";
+    
+    static protected final String FLASH_CURRENT_MAP_KEY = FlashImpl.class.getName()
+            + ".CURRENTMAP.KEY";
+
+    static protected final String FLASH_POSTBACK_MAP_CACHE = FlashImpl.class.getName()
+            + ".POSTBACKMAP.CACHE";
+
+    static protected final String FLASH_POSTBACK_MAP_KEY = FlashImpl.class.getName()
+            + ".POSTBACKMAP.KEY";
+    
+    static private final char SEPARATOR_CHAR = '.';
+
+    // the current token value
+    private final AtomicLong _count;
+
+    public FlashImpl()
+    {
+        _count = new AtomicLong(_getSeed());
+    }
+
+    /**
+     * Returns a cryptographically secure random number to use as the _count seed
+     */
+    static long _getSeed()
+    {
+        SecureRandom rng;
+        try
+        {
+            // try SHA1 first
+            rng = SecureRandom.getInstance("SHA1PRNG");
+        }
+        catch (NoSuchAlgorithmException e)
+        {
+            // SHA1 not present, so try the default (which could potentially not be
+            // cryptographically secure)
+            rng = new SecureRandom();
+        }
+
+        // use 48 bits for strength and fill them in
+        byte[] randomBytes = new byte[6];
+        rng.nextBytes(randomBytes);
+
+        // convert to a long
+        return new BigInteger(randomBytes).longValue();
+    }
+
+    /**
+     * Get the next token to be assigned to this request
+     * 
+     * @return
+     */
+    String _getNextToken()
+    {
+        // atomically increment the value
+        long nextToken = _count.incrementAndGet();
+
+        // convert using base 36 because it is a fast efficient subset of base-64
+        return Long.toString(nextToken, 36);
+    }
+
+    /**
+     * Return a Flash instance from the application map
+     * 
+     * @param context
+     * @return
+     */
+    public static Flash getCurrentInstance(ExternalContext context)
+    {
+        Map<String, Object> applicationMap = context.getApplicationMap();
+        Flash flash = (Flash) applicationMap.get(FLASH_INSTANCE);
+
+        synchronized (applicationMap)
+        {
+            if (flash == null)
+            {
+                flash = new FlashImpl();
+                context.getApplicationMap().put(FLASH_INSTANCE, flash);
+            }
+        }
+        return flash;
+    }
+
+    /**
+     * Return a wrapper from the session map used to implement flash maps
+     * for more information see SubKeyMap doc
+     */
+    @SuppressWarnings("unchecked")
+    Map<String, Object> _getMapFromSession(FacesContext context,
+            String token, boolean createIfNeeded)
+    {
+        ExternalContext external = context.getExternalContext();
+        Object session = external.getSession(true);
+
+        Map<String, Object> map = null;
+
+        // Synchronize on the session object to ensure that
+        // we don't ever create two different caches
+        synchronized (session)
+        {
+            map = (Map<String, Object>) external.getSessionMap().get(token);
+            if ((map == null) && createIfNeeded)
+            {
+                map = new SubKeyMap<Object>(context.getExternalContext()
+                        .getSessionMap(), token);
+            }
+        }
+
+        return map;
+    }
+
+    /**
+     * Return the flash map created on this traversal. This one will be sent
+     * on next request, so it will be retrieved as postback map of the next
+     * request.
+     * 
+     * Note it is supposed that FLASH_CURRENT_MAP_KEY is initialized before
+     * restore view phase (see doPrePhaseActions() for details).
+     * 
+     * @param context
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    Map<String, Object> getCurrentRequestMap(FacesContext context)
+    {
+        Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+        Map<String, Object> map = (Map<String, Object>) requestMap.get(FLASH_CURRENT_MAP_CACHE);
+        if (map == null)
+        {
+            String token = (String) requestMap.get(FLASH_CURRENT_MAP_KEY);
+            String fullToken = FLASH_SCOPE_CACHE + SEPARATOR_CHAR + token;
+            map =  _getMapFromSession(context, fullToken, true);
+            requestMap.put(FLASH_CURRENT_MAP_CACHE, map);
+        }
+        return map;
+    }
+    
+    @SuppressWarnings("unchecked")
+    Map<String, Object> getPostbackRequestMap(FacesContext context)
+    {
+        Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+        Map<String, Object> map = (Map<String, Object>) requestMap.get(FLASH_POSTBACK_MAP_CACHE);
+        if (map == null)
+        {
+            String token = (String) requestMap.get(FLASH_POSTBACK_MAP_KEY);
+            if (token == null && isRedirect())
+            {
+                // In post-redirect-get, request values are reset, so we need
+                // to get the postback key again.
+                token = _getPostbackMapKey(context.getExternalContext());
+            }
+            String fullToken = FLASH_SCOPE_CACHE + SEPARATOR_CHAR + token;
+            map =  _getMapFromSession(context, fullToken, true);
+            requestMap.put(FLASH_POSTBACK_MAP_CACHE, map);
+        }
+        return map;
+    }
+    
+    /**
+     * Get the proper map according to the current phase:
+     * 
+     * Normal case:
+     * 
+     * - First request, restore view phase (create a new one): current map n
+     * - First request, execute phase: Skipped
+     * - First request, render  phase: current map n
+     * 
+     *   Current map n saved and put as postback map n
+     * 
+     * - Second request, execute phase: postback map n
+     * - Second request, render  phase: current map n+1
+     * 
+     * Post Redirect Get case: Redirect is triggered by a call to setRedirect(true) from NavigationHandler
+     * or earlier using c:set tag.
+     * 
+     * - First request, restore view phase (create a new one): current map n
+     * - First request, execute phase: Skipped
+     * - First request, render  phase: current map n
+     * 
+     *   Current map n saved and put as postback map n
+     * 
+     * POST
+     * 
+     * - Second request, execute phase: postback map n
+     * 
+     * REDIRECT
+     * 
+     * - NavigationHandler do the redirect, requestMap data lost, called Flash.setRedirect(true)
+     * 
+     *   Current map n saved and put as postback map n
+     * 
+     * GET
+     * 
+     * - Third  request, restore view phase (create a new one): current map n+1 
+     *   (isRedirect() should return true as javadoc says)
+     * - Third  request, execute phase: skipped
+     * - Third  request, render  phase: current map n+1
+     * 
+     * In this way proper behavior is preserved even in the case of redirect, since the GET part is handled as
+     * the "render" part of the current traversal, keeping the semantic of flash object.
+     * 
+     * @return
+     */
+    Map<String, Object> getCurrentPhaseMap()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()) ||
+            !facesContext.isPostback() || isRedirect())
+        {
+            return getCurrentRequestMap(facesContext);
+        }
+        else
+        {
+            return getPostbackRequestMap(facesContext);
+        }
+    }
+    
+    void _removeAllChildren(FacesContext facesContext)
+    {
+        Map<String, Object> map = getPostbackRequestMap(facesContext);
+        
+        // Clear everything - note that because of naming conventions,
+        // this will in fact automatically recurse through all children
+        // grandchildren etc. - which is kind of a design flaw of SubKeyMap,
+        // but one we're relying on
+        map.clear();
+    }
+
+    /**
+     * 
+     */
+    @Override
+    public void doPrePhaseActions(FacesContext facesContext)
+    {
+        Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+        
+        if (PhaseId.RESTORE_VIEW.equals(facesContext.getCurrentPhaseId()))
+        {
+            // Generate token and put on requestMap
+            // It is necessary to set this token always, because on the next request
+            // it should be possible to change postback map.
+            String currentToken = _getNextToken();
+            requestMap.put(FLASH_CURRENT_MAP_KEY, currentToken);
+            
+            if (facesContext.isPostback())
+            {
+                //Retore token
+                String previousToken = _getPostbackMapKey(facesContext.getExternalContext());
+                
+                if (previousToken != null)
+                {
+                    requestMap.put(FLASH_POSTBACK_MAP_KEY, previousToken);
+                }
+            }
+        }
+        
+        //
+        if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()))
+        {
+            // Put current map on next previous map
+            // but only if this request is not a redirect
+            if (!isRedirect())
+            {
+                _addPostbackMapKey(facesContext.getExternalContext());
+            }
+        }
+    }
+    
+    @Override
+    public void doPostPhaseActions(FacesContext facesContext)
+    {
+        // TODO Auto-generated method stub
+        if (PhaseId.RENDER_RESPONSE.equals(facesContext.getCurrentPhaseId()))
+        {
+            //Remove previous flash from session
+            Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+            String token = (String) requestMap.get(FLASH_POSTBACK_MAP_KEY);
+            
+            if (token != null)
+            {
+                _removeAllChildren(facesContext);
+            }
+        }
+    }
+    
+    //private void _addPreviousToken
+    
+    /**
+     * Retrieve the postback map key
+     */
+    String _getPostbackMapKey(ExternalContext externalContext)
+    {
+        String token = null;
+        Object response = externalContext.getResponse();
+        if (response instanceof HttpServletResponse)
+        {
+            //Use a cookie
+            Cookie cookie = (Cookie) externalContext.getRequestCookieMap().get(FLASH_POSTBACK_MAP_KEY);
+            if (cookie != null)
+            {
+                token = cookie.getValue();
+            }
+        }
+        else
+        {
+            //Use HttpSession or PortletSession object
+            Map<String, Object> sessionMap = externalContext.getSessionMap();
+            token = (String) sessionMap.get(FLASH_POSTBACK_MAP_KEY);
+        }
+        return token;
+    }
+    
+    /**
+     * Take the current map key and store it as a postback key for the next request.
+     * 
+     * @param externalContext
+     */
+    void _addPostbackMapKey(ExternalContext externalContext)
+    {
+        Object response = externalContext.getResponse();
+        String token = (String) externalContext.getRequestMap().get(FLASH_CURRENT_MAP_KEY);
+        if (response instanceof HttpServletResponse)
+        {
+            Cookie cookie = new Cookie(FLASH_POSTBACK_MAP_KEY,token);
+            cookie.setMaxAge(-1);
+            ((HttpServletResponse)response).addCookie(cookie);
+        }
+        else
+        {
+            //Use HttpSession or PortletSession object
+            Map<String, Object> sessionMap = externalContext.getSessionMap();
+            sessionMap.put(FLASH_POSTBACK_MAP_KEY, token);
+        }
+    }
+    
+    
+    /**
+     * For check if there is a redirect we to take into accout this points:
+     * 
+     * 1. isRedirect() could be accessed many times during the same
+     *    request.
+     * 2. According to Post-Redirect-Get pattern, we cannot 
+     * ensure request scope values are preserved.
+     * 
+     */
+    @Override
+    public boolean isRedirect()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ExternalContext externalContext = facesContext.getExternalContext();
+        Map<String, Object> requestMap = externalContext.getRequestMap();
+        Boolean redirect = (Boolean) requestMap.get(FLASH_REDIRECT);
+        if (redirect == null)
+        {
+            Object response = externalContext.getResponse();
+            if (response instanceof HttpServletResponse)
+            {
+                // Request values are lost after a redirect. We can create a 
+                // temporal cookie to pass the params between redirect calls.
+                // It is better than use HttpSession object, because this cookie
+                // is never sent by the server.
+                Cookie cookie = (Cookie) externalContext.getRequestCookieMap()
+                        .get(FLASH_REDIRECT);
+                if (cookie != null)
+                {
+                    redirect = Boolean.TRUE;
+                    HttpServletResponse httpResponse = (HttpServletResponse) response;
+                    // A redirect happened, so it is safe to remove the cookie, setting
+                    // the maxAge to 0 seconds. The effect is we passed FLASH_REDIRECT param 
+                    // to this request object
+                    cookie.setMaxAge(0);
+                    cookie.setValue(null);
+                    httpResponse.addCookie(cookie);
+                    requestMap.put(FLASH_REDIRECT, redirect);
+                }
+                else
+                {
+                    redirect = Boolean.FALSE;
+                }
+            }
+            else
+            {
+                // Note that on portlet world we can't create cookies,
+                // so we are forced to use the session map. Anyway, 
+                // according to the Bridge implementation(for example see 
+                // org.apache.myfaces.portlet.faces.bridge.BridgeImpl)
+                // session object is created at start faces request
+                Map<String, Object> sessionMap = externalContext
+                        .getSessionMap();
+                redirect = (Boolean) sessionMap.get(FLASH_REDIRECT);
+                if (redirect != null)
+                {
+                    sessionMap.remove(FLASH_REDIRECT);
+                    requestMap.put(FLASH_REDIRECT, redirect);
+                }
+                else
+                {
+                    redirect = Boolean.FALSE;
+                }
+            }
+        }
+        return redirect;
+    }
+
+    @Override
+    public void setRedirect(boolean redirect)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ExternalContext externalContext = facesContext.getExternalContext();
+        Map<String, Object> requestMap = externalContext.getRequestMap();
+        
+        Boolean previousRedirect = (Boolean) requestMap.get(FLASH_REDIRECT);
+        previousRedirect = (previousRedirect == null) ? Boolean.FALSE : previousRedirect;
+        
+        if (!previousRedirect.booleanValue() && redirect)
+        {
+            // This request contains a redirect. This condition is in general 
+            // triggered by a NavigationHandler. After a redirect all request scope
+            // values get lost, so in order to preserve this value we need to
+            // pass it between request. One strategy is use a cookie that is never sent
+            // to the client. Other alternative is use the session map.
+            Object response = externalContext.getResponse();
+            if (response instanceof HttpServletResponse)
+            {
+                HttpServletResponse servletResponse = (HttpServletResponse) response;
+                Cookie cookie = new Cookie(FLASH_REDIRECT,"true");
+                cookie.setMaxAge(-1);
+                servletResponse.addCookie(cookie);
+            }
+            else
+            {
+                externalContext.getSessionMap().put(FLASH_REDIRECT, redirect);
+            }
+        }
+        requestMap.put(FLASH_REDIRECT, redirect);
+    }
+
+    /**
+     * In few words take a value from request scope map and put it on current request map,
+     * so it is visible on the next request.
+     */
+    @Override
+    public void keep(String key)
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
+        Object value = requestMap.get(key);
+        getCurrentRequestMap(facesContext).put(key, value);
+    }
+
+    /**
+     * This is just an alias for request scope map.
+     */
+    @Override
+    public void putNow(String key, Object value)
+    {
+        FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(key, value);
+    }
+
+    @Override
+    public boolean isKeepMessages()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+    
+    @Override
+    public void setKeepMessages(boolean newValue)
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void clear()
+    {
+        getCurrentPhaseMap().clear();
+    }
+
+    @Override
+    public boolean containsKey(Object key)
+    {
+        return getCurrentPhaseMap().containsKey(key);
+    }
+
+    @Override
+    public boolean containsValue(Object value)
+    {
+        return getCurrentPhaseMap().containsValue(value);
+    }
+
+    @Override
+    public Set<java.util.Map.Entry<String, Object>> entrySet()
+    {
+        return getCurrentPhaseMap().entrySet();
+    }
+
+    @Override
+    public Object get(Object key)
+    {
+        if (key == null)
+            return null;
+        
+        if ("keepMessages".equals(key))
+        {
+            return isKeepMessages();
+        }
+        else if ("redirect".equals(key))
+        {
+            return isRedirect();
+        }
+        
+        FacesContext context = FacesContext.getCurrentInstance();
+        Map<String, Object> postbackMap = getPostbackRequestMap(context);
+        Object returnValue = null;
+        
+        if (postbackMap != null)
+        {
+            returnValue = postbackMap.get(key);
+        }
+         
+        return returnValue;
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return getCurrentPhaseMap().isEmpty();
+    }
+
+    @Override
+    public Set<String> keySet()
+    {
+        return getCurrentPhaseMap().keySet();
+    }
+
+    @Override
+    public Object put(String key, Object value)
+    {
+        if (key == null)
+            return null;
+        
+        if ("keepMessages".equals(key))
+        {
+            Boolean booleanValue = convertToBoolean(value);
+            this.setKeepMessages(booleanValue);
+            return booleanValue;
+        }
+        else if ("redirect".equals(key))
+        {
+            Boolean booleanValue = convertToBoolean(value);
+            this.setRedirect(booleanValue);
+            return booleanValue;
+        }
+        else
+        {
+            Object returnValue = getCurrentPhaseMap().put(key, value); 
+            return returnValue;
+        }
+    }
+
+    private Boolean convertToBoolean(Object value)
+    {
+        Boolean booleanValue;
+        if (value instanceof Boolean)
+        {
+            booleanValue = (Boolean) value;
+        }
+        else
+        {
+            booleanValue = Boolean.parseBoolean(value.toString());
+        }
+        return booleanValue;
+    }
+
+    @Override
+    public void putAll(Map<? extends String, ? extends Object> m)
+    {
+        getCurrentPhaseMap().putAll(m);
+    }
+
+    @Override
+    public Object remove(Object key)
+    {
+        return getCurrentPhaseMap().remove(key);
+    }
+
+    @Override
+    public int size()
+    {
+        return getCurrentPhaseMap().size();
+    }
+
+    @Override
+    public Collection<Object> values()
+    {
+        return getCurrentPhaseMap().values();
+    }
+    
+}

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/FlashImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java?rev=791709&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java Tue Jul  7 05:40:32 2009
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.context.flash;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * NOTE: Class copied from trinidad to be used on FlashImpl.
+ * 
+ * Map that wraps another to provide an isolated namespace using
+ * a prefix.  This is especially handy for storing properties on
+ * the session in a structured manner without putting them into
+ * a true "Map" - because storing in a Map breaks session failover.
+ * (Session failover won't trigger on mutations of contained objects.)
+ * <p>
+ * Note that there is a potential design flaw;  if you create a SubKeyMap
+ * for "mypackage.foo" and for "mypackage.foo.bar", all the keys in the
+ * latter will actually show up in the former (prefixed by ".bar").  This
+ * "flaw" is actually relied on by PageFlowScopeMap (since it provides
+ * a handy way to clear out all descendents), so don't "fix" it!
+ */
+final class SubKeyMap<V> extends AbstractMap<String, V>
+{
+    public SubKeyMap(Map<String, Object> base, String prefix)
+    {
+        if (base == null)
+            throw new NullPointerException();
+        if (prefix == null)
+            throw new NullPointerException();
+
+        // Optimize the scenario where we're wrapping another SubKeyMap
+        if (base instanceof SubKeyMap)
+        {
+            _base = ((SubKeyMap) base)._base;
+            _prefix = ((SubKeyMap) base)._prefix + prefix;
+        }
+        else
+        {
+            _base = base;
+            _prefix = prefix;
+        }
+    }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return entrySet().isEmpty();
+    }
+
+    @Override
+    public V get(Object key)
+    {
+        key = _getBaseKey(key);
+        return (V) _base.get(key);
+    }
+
+    @Override
+    public V put(String key, V value)
+    {
+        key = _getBaseKey(key);
+        return (V) _base.put(key, value);
+    }
+
+    @Override
+    public V remove(Object key)
+    {
+        key = _getBaseKey(key);
+        return (V) _base.remove(key);
+    }
+
+    @Override
+    public boolean containsKey(Object key)
+    {
+        if (!(key instanceof String))
+            return false;
+
+        return _base.containsKey(_getBaseKey(key));
+    }
+
+    @Override
+    public Set<Map.Entry<String, V>> entrySet()
+    {
+        if (_entrySet == null)
+            _entrySet = new Entries<V>();
+        return _entrySet;
+    }
+
+    private String _getBaseKey(Object key)
+    {
+        if (key == null)
+            throw new NullPointerException();
+        // Yes, I want a ClassCastException if it's not a String
+        return _prefix + ((String) key);
+    }
+
+    private List<String> _gatherKeys()
+    {
+        List<String> list = new ArrayList<String>();
+        for (String key : _base.keySet())
+        {
+            if (key != null && key.startsWith(_prefix))
+                list.add(key);
+        }
+
+        return list;
+    }
+
+    //
+    // Set implementation for SubkeyMap.entrySet()
+    //
+    private class Entries<V> extends AbstractSet<Map.Entry<String, V>>
+    {
+        public Entries()
+        {
+        }
+
+        @Override
+        public Iterator<Map.Entry<String, V>> iterator()
+        {
+            // Sadly, if you just try to use a filtering approach
+            // on the iterator, you'll get concurrent modification
+            // exceptions.  Consequently, gather the keys in a list
+            // and iterator over that.
+            List<String> keyList = _gatherKeys();
+            return new EntryIterator<V>(keyList.iterator());
+        }
+
+        @Override
+        public int size()
+        {
+            int size = 0;
+            for (String key : _base.keySet())
+            {
+                if (key != null && key.startsWith(_prefix))
+                    size++;
+            }
+
+            return size;
+        }
+
+        @Override
+        public boolean isEmpty()
+        {
+            Iterator<String> keys = _base.keySet().iterator();
+            while (keys.hasNext())
+            {
+                String key = keys.next();
+                // Short-circuit:  the default implementation would always
+                // need to iterate to find the total size.
+                if (key != null && key.startsWith(_prefix))
+                    return false;
+            }
+
+            return true;
+        }
+
+        @Override
+        public void clear()
+        {
+            Iterator<String> keys = _base.keySet().iterator();
+            while (keys.hasNext())
+            {
+                String key = keys.next();
+                if (key != null && key.startsWith(_prefix))
+                {
+                    keys.remove();
+                }
+            }
+        }
+    }
+
+    private class EntryIterator<V> implements Iterator<Map.Entry<String, V>>
+    {
+        public EntryIterator(Iterator<String> iterator)
+        {
+            _iterator = iterator;
+        }
+
+        public boolean hasNext()
+        {
+            return _iterator.hasNext();
+        }
+
+        public Map.Entry<String, V> next()
+        {
+            String baseKey = _iterator.next();
+            _currentKey = baseKey;
+            return new Entry<V>(baseKey);
+        }
+
+        public void remove()
+        {
+            if (_currentKey == null)
+                throw new IllegalStateException();
+
+            _base.remove(_currentKey);
+
+            _currentKey = null;
+        }
+
+        private Iterator<String> _iterator;
+        private String _currentKey;
+    }
+
+    private class Entry<V> implements Map.Entry<String, V>
+    {
+        public Entry(String baseKey)
+        {
+            _baseKey = baseKey;
+        }
+
+        public String getKey()
+        {
+            if (_key == null)
+                _key = _baseKey.substring(_prefix.length());
+            return _key;
+        }
+
+        public V getValue()
+        {
+            return (V) _base.get(_baseKey);
+        }
+
+        public V setValue(V value)
+        {
+            return (V) _base.put(_baseKey, value);
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean equals(Object o)
+        {
+            if (!(o instanceof Map.Entry))
+                return false;
+            Map.Entry<String, V> e = (Map.Entry<String, V>) o;
+            return _equals(getKey(), e.getKey())
+                    && _equals(getValue(), e.getValue());
+        }
+
+        @Override
+        public int hashCode()
+        {
+            Object key = getKey();
+            Object value = getValue();
+            return ((key == null) ? 0 : key.hashCode())
+                    ^ ((value == null) ? 0 : value.hashCode());
+        }
+
+        private String _baseKey;
+        private String _key;
+    }
+
+    static private boolean _equals(Object a, Object b)
+    {
+        if (a == null)
+            return b == null;
+        return a.equals(b);
+    }
+
+    private final Map<String, Object> _base;
+    private final String _prefix;
+    private Set<Map.Entry<String, V>> _entrySet;
+
+}

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/flash/SubKeyMap.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/ServletExternalContextImpl.java Tue Jul  7 05:40:32 2009
@@ -38,6 +38,7 @@
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+import javax.faces.context.Flash;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -49,6 +50,7 @@
 import javax.servlet.http.HttpSession;
 
 import org.apache.myfaces.context.ReleaseableExternalContext;
+import org.apache.myfaces.context.flash.FlashImpl;
 import org.apache.myfaces.util.EnumerationIterator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -895,4 +897,12 @@
 
         return newUrl.toString();
     }
+    
+    /**
+     * @since 2.0
+     */
+    public Flash getFlash()
+    {
+        return FlashImpl.getCurrentInstance(this);
+    }
 }

Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java?rev=791709&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java Tue Jul  7 05:40:32 2009
@@ -0,0 +1,315 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.el;
+
+import java.beans.FeatureDescriptor;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.Flash;
+
+/**
+ * Resolver for Flash object 
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FlashELResolver extends ELResolver
+{
+
+    private final static String FLASH = "flash".intern();
+
+    private final static String KEEP = "keep".intern();
+
+    private final static String NOW = "now".intern();
+
+    public FlashELResolver()
+    {
+        super();
+    }
+
+    @Override
+    public void setValue(ELContext context, Object base, Object property,
+            Object value) throws NullPointerException,
+            PropertyNotFoundException, PropertyNotWritableException,
+            ELException
+    {
+        if (property == null)
+            throw new PropertyNotFoundException();
+        if (!(property instanceof String))
+            return;
+
+        String strProperty = castAndIntern(property);
+
+        if (FLASH.equals(strProperty))
+        {
+            throw new PropertyNotWritableException();
+        }
+        else if (base instanceof Flash)
+        {
+            context.setPropertyResolved(true);
+            try
+            {
+                ((Flash) base).put(strProperty, value);
+            }
+            catch (UnsupportedOperationException e)
+            {
+                throw new PropertyNotWritableException(e);
+            }
+        }
+    }
+
+    @Override
+    public boolean isReadOnly(ELContext context, Object base, Object property)
+            throws NullPointerException, PropertyNotFoundException, ELException
+    {
+
+        if (property == null)
+            throw new PropertyNotFoundException();
+        if (!(property instanceof String))
+            return false;
+
+        String strProperty = castAndIntern(property);
+
+        if (FLASH.equals(strProperty))
+        {
+            context.setPropertyResolved(true);
+            return true;
+        }
+        else if (base instanceof Flash) {
+            context.setPropertyResolved(true);
+        }
+
+        return false;
+    }
+
+    @Override
+    public Object getValue(ELContext elContext, Object base, Object property)
+            throws NullPointerException, PropertyNotFoundException, ELException
+    {
+
+        if (property == null)
+            throw new PropertyNotFoundException();
+        if (!(property instanceof String))
+            return null;
+
+        String strProperty = castAndIntern(property);
+
+        if (base == null)
+        {
+            if (FLASH.equals(strProperty))
+            {
+                //Access to flash object
+                elContext.setPropertyResolved(true);
+                Flash flash = externalContext(elContext).getFlash();
+                //This is just to make sure after this point
+                //we are not in "keep" promotion.
+                setDoKeepPromotion(false);
+                
+                // Note that after this object is returned, Flash.get() and Flash.put()
+                // methods are called from javax.el.MapELResolver, since 
+                // Flash is instance of Map.
+                return flash;
+            }
+        }
+        else if (base instanceof Flash)
+        {
+            Flash flash = (Flash) base;
+            if (KEEP.equals(strProperty))
+            {
+                setDoKeepPromotion(true);
+                // Since we returned a Flash instance getValue will 
+                // be called again but this time the property name
+                // to be resolved will be called, so we can do keep
+                // promotion.
+                return base;
+            }
+            else if (NOW.equals(strProperty))
+            {
+                //Prevent invalid syntax #{flash.keep.now.someKey}
+                if (!isDoKeepPromotion())
+                {
+                    // According to the javadoc of Flash.putNow() and 
+                    // Flash.keep(), this is an alias to requestMap, used
+                    // as a "buffer" to promote vars to flash scope using
+                    // "keep" method
+                    elContext.setPropertyResolved(true);
+                    return externalContext(elContext).getRequestMap();
+                }
+            }
+            else if (isDoKeepPromotion())
+            {
+                //Resolve property calling get or keep
+                elContext.setPropertyResolved(true);
+                //Obtain the value on requestMap if any
+                Object value = externalContext(elContext).getRequestMap().get(strProperty);
+                //promote it to flash scope
+                flash.keep(strProperty);
+                return value;
+            }
+            else
+            {
+                //Just get the value
+                elContext.setPropertyResolved(true);
+                return flash.get(strProperty);
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * This var indicate if we are inside a keep operation
+     * or not. We go into keep status in two cases:
+     * 
+     * - A direct call to Flash.keep(String key)
+     * - A lookup to keep map using a value expression #{flash.keep.someKey}.
+     *   This occur when the ELResolver try to get the keep object.
+     *   
+     * Note that when "keep" is resolved by FlashELResolver,
+     * we need a way to comunicate that the current lookup is 
+     * for keep promotion.
+     * 
+     * This var do the job.
+     */
+    private static ThreadLocal<Boolean> _keepStatus = 
+        new ThreadLocal<Boolean>()
+        {
+            @Override
+            protected Boolean initialValue()
+            {
+                return Boolean.FALSE;
+            }
+        };
+
+    private static boolean isDoKeepPromotion()
+    {
+        return _keepStatus.get();
+    }
+
+    private static void setDoKeepPromotion(boolean value)
+    {
+        _keepStatus.set(Boolean.valueOf(value));
+    }
+    
+    // get the FacesContext from the ELContext
+    protected FacesContext facesContext(ELContext context)
+    {
+        return (FacesContext) context.getContext(FacesContext.class);
+    }
+
+    protected ExternalContext externalContext(ELContext context)
+    {
+        return facesContext(context).getExternalContext();
+    }
+
+    @Override
+    public Class<?> getType(ELContext context, Object base, Object property)
+            throws NullPointerException, PropertyNotFoundException, ELException
+    {
+
+        if (property == null)
+            throw new PropertyNotFoundException();
+        if (!(property instanceof String))
+            return null;
+
+        String strProperty = castAndIntern(property);
+
+        if (FLASH.equals(strProperty))
+        {
+            context.setPropertyResolved(true);
+        }
+        else if (base instanceof Flash) {
+            context.setPropertyResolved(true);
+            Object obj = ((Flash) base).get(property);
+            return (obj != null) ? obj.getClass() : null;
+        }
+
+        return null;
+    }
+
+    @Override
+    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
+            Object base)
+    {
+        ArrayList<FeatureDescriptor> descriptors = new ArrayList<FeatureDescriptor>(
+                1);
+
+        descriptors.add(makeDescriptor(FLASH,
+                "Represents the current flash scope", Object.class));
+
+        if (base instanceof Flash) {
+            Iterator itr = ((Flash) base).keySet().iterator();
+            Object key;
+            FeatureDescriptor desc;
+            while (itr.hasNext()) {
+                key = itr.next();
+                desc = makeDescriptor(key.toString(), key.toString(), key.getClass());
+                descriptors.add(desc);
+            }
+        }
+        return descriptors.iterator();
+    }
+
+    protected FeatureDescriptor makeDescriptor(String name, String description,
+            Class<?> elResolverType)
+    {
+        FeatureDescriptor fd = new FeatureDescriptor();
+        fd.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);
+        fd.setValue(ELResolver.TYPE, elResolverType);
+        fd.setName(name);
+        fd.setDisplayName(name);
+        fd.setShortDescription(description);
+        fd.setExpert(false);
+        fd.setHidden(false);
+        fd.setPreferred(true);
+        return fd;
+    }
+
+    @Override
+    public Class<?> getCommonPropertyType(ELContext context, Object base)
+    {
+        if (base == null)
+            return null;
+
+        if (base instanceof Flash)
+        {
+            return Object.class;
+        }
+        else if (FLASH.equals(base.toString()))
+        {
+            return Object.class;
+        }
+
+        return null;
+    }
+
+    protected String castAndIntern(Object o)
+    {
+        String s = (String) o;
+        return s.intern();
+    }
+
+}

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/FlashELResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java Tue Jul  7 05:40:32 2009
@@ -18,13 +18,6 @@
  */
 package org.apache.myfaces.el.unified;
 
-import org.apache.myfaces.config.RuntimeConfig;
-import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
-import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
-import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
-import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
-import org.apache.myfaces.el.unified.resolver.ResourceResolver;
-
 import javax.el.ArrayELResolver;
 import javax.el.BeanELResolver;
 import javax.el.CompositeELResolver;
@@ -32,6 +25,14 @@
 import javax.el.MapELResolver;
 import javax.el.ResourceBundleELResolver;
 
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.el.FlashELResolver;
+import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
+import org.apache.myfaces.el.unified.resolver.ResourceResolver;
+import org.apache.myfaces.el.unified.resolver.ScopedAttributeResolver;
+import org.apache.myfaces.el.unified.resolver.implicitobject.ImplicitObjectResolver;
+
 /**
  * Create the el resolver for faces. see 1.2 spec section 5.6.2
  * 
@@ -52,6 +53,9 @@
 
         addFromRuntimeConfig(elResolver);
 
+        //Flash object is instanceof Map, so it is necessary to resolve
+        //before MapELResolver. Better to put this one before
+        elResolver.add(new FlashELResolver());
         elResolver.add(new ManagedBeanResolver());
         elResolver.add(new ResourceBundleELResolver());
         elResolver.add(new ResourceBundleResolver());

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java Tue Jul  7 05:40:32 2009
@@ -21,6 +21,7 @@
 import javax.el.CompositeELResolver;
 
 import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.el.FlashELResolver;
 import org.apache.myfaces.el.unified.resolver.ManagedBeanResolver;
 import org.apache.myfaces.el.unified.resolver.ResourceBundleResolver;
 import org.apache.myfaces.el.unified.resolver.ResourceResolver;
@@ -43,6 +44,9 @@
     public void build(CompositeELResolver elResolver)
     {
         elResolver.add(ImplicitObjectResolver.makeResolverForJSP());
+        //Flash object is instanceof Map, so it is necessary to resolve
+        //before MapELResolver. Better to put this one before
+        elResolver.add(new FlashELResolver());        
         elResolver.add(new ManagedBeanResolver());
         elResolver.add(new ResourceBundleResolver());
         elResolver.add(new ResourceResolver());

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleImpl.java?rev=791709&r1=791708&r2=791709&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleImpl.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/lifecycle/LifecycleImpl.java Tue Jul  7 05:40:32 2009
@@ -23,6 +23,7 @@
 
 import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
+import javax.faces.context.Flash;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 import javax.faces.lifecycle.Lifecycle;
@@ -95,6 +96,7 @@
         }
 
         PhaseId currentPhaseId = executor.getPhase();
+        Flash flash = context.getExternalContext().getFlash();
 
         try
         {
@@ -105,6 +107,8 @@
              * phase as the first instruction at the beginning of each phase
              */
             context.setCurrentPhaseId(currentPhaseId);
+            
+            flash.doPrePhaseActions(context);
 
             phaseListenerMgr.informPhaseListenersBefore(currentPhaseId);
 
@@ -126,6 +130,8 @@
         finally
         {
             phaseListenerMgr.informPhaseListenersAfter(currentPhaseId);
+            
+            flash.doPostPhaseActions(context);
         }
 
         if (isResponseComplete(context, currentPhaseId, false) || shouldRenderResponse(context, currentPhaseId, false))
@@ -154,9 +160,13 @@
             log.trace("entering " + renderExecutor.getPhase() + " in " + LifecycleImpl.class.getName());
 
         PhaseListenerManager phaseListenerMgr = new PhaseListenerManager(this, facesContext, getPhaseListeners());
-
+        Flash flash = facesContext.getExternalContext().getFlash();
+        
         try
         {
+            facesContext.setCurrentPhaseId(renderExecutor.getPhase());
+            
+            flash.doPrePhaseActions(facesContext);
             phaseListenerMgr.informPhaseListenersBefore(renderExecutor.getPhase());
             // also possible that one of the listeners completed the response
             if (isResponseComplete(facesContext, renderExecutor.getPhase(), true))
@@ -169,6 +179,7 @@
         finally
         {
             phaseListenerMgr.informPhaseListenersAfter(renderExecutor.getPhase());
+            flash.doPostPhaseActions(facesContext);
         }
 
         if (log.isTraceEnabled())

Added: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java?rev=791709&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java Tue Jul  7 05:40:32 2009
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.context.flash;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import org.apache.myfaces.context.flash.FlashImpl;
+import org.apache.shale.test.base.AbstractViewControllerTestCase;
+
+public class FlashImplTest extends AbstractViewControllerTestCase
+{
+
+    public FlashImplTest(String name)
+    {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testSessionMapWrapperSubKeyMap() throws Exception
+    {
+        FlashImpl flash = (FlashImpl) FlashImpl.getCurrentInstance(externalContext);
+        
+        String currentToken = flash._getNextToken();
+        
+        externalContext.getRequestMap().put(FlashImpl.FLASH_CURRENT_MAP_KEY, currentToken);
+        
+        Map<String,Object> currentMap = flash.getCurrentRequestMap(facesContext);
+        
+        currentMap.put("testkey1", "testvalue1");
+        
+        assertEquals("testvalue1", currentMap.get("testkey1"));
+        
+        assertEquals("testvalue1", session.getAttribute(FlashImpl.FLASH_SCOPE_CACHE + '.' + currentToken + "testkey1"));        
+    }
+}

Propchange: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/flash/FlashImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL