Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (C) 2014 Zach Melamed
  * 
  * Latest version available online at https://github.com/zach-m/tectonica-commons
  *
  * 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.
 */
package com.tectonica.gae;
PhaseListener to ensure the HttpSession data is written to the datastore.

To use, add the following to your faces-config.xml:

 <lifecycle>
    <phase-listener>com.tectonica.gae.GaePhaseListener</phase-listener>
 </lifecycle>
 
If properly configured, an application deployed on GAE platform can leverage HttpSessions to store data between requests. Session data is stored in the datastore and memcache is also used for speed. Session data is persisted at the end of the request.

The App Engine session implementation will not recognize if properties of objects stored in the session are changed which is why we have this PhaseListener which will modify a session attribute with the current date and time (in milliseconds) at the end of every phase.

See also:
https://developers.google.com/appengine/docs/java/config/appconfig.Java_appengine_web_xml_Enabling_sessions
http://stackoverflow.com/questions/19259457/session-lost-in-google-app-engine-using-jsf
public class GaePhaseListener implements PhaseListener
	private static final long serialVersionUID = 1L;
	public void afterPhase(PhaseEvent event)
	{
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("CURRENT_TIME", System.currentTimeMillis());
	}
	public void beforePhase(PhaseEvent event)
	{}
	public PhaseId getPhaseId()
	{
	}
New to GrepCode? Check out our FAQ X