You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/11/17 19:20:12 UTC
svn commit: r881431 -
/incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
Author: gerdogdu
Date: Tue Nov 17 18:20:12 2009
New Revision: 881431
URL: http://svn.apache.org/viewvc?rev=881431&view=rev
Log:
Adding JSF based view handler for JSF 2.0 conversation propogation. Thanks to Sven Linstaedt for patching.
Added:
incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java (with props)
Added: incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java?rev=881431&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java (added)
+++ incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java Tue Nov 17 18:20:12 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.webbeans.jsf;
+
+import java.util.Set;
+
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.faces.application.ViewHandler;
+import javax.faces.application.ViewHandlerWrapper;
+import javax.faces.context.FacesContext;
+
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.util.JSFUtil;
+
+public class ConversationAwareViewHandler extends ViewHandlerWrapper
+{
+ private final ViewHandler delegate;
+
+ public ConversationAwareViewHandler(ViewHandler delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getActionURL(FacesContext context, String viewId)
+ {
+ String url = delegate.getActionURL(context, viewId);
+
+ Conversation conversation = lookupConversation();
+ if (conversation != null && !conversation.isTransient())
+ {
+ url = JSFUtil.getRedirectViewIdWithCid(url, conversation.getId());
+ }
+
+ return url;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ViewHandler getWrapped()
+ {
+ return delegate;
+ }
+
+ private Conversation lookupConversation()
+ {
+ BeanManager beanManager = BeanManagerImpl.getManager();
+ if (beanManager == null)
+ {
+ return null;
+ }
+
+ Set<Bean<?>> beans = beanManager.getBeans(Conversation.class, new AnnotationLiteral<Default>() {});
+ if (beans.isEmpty())
+ {
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ Bean<Conversation> conversationBean = (Bean<Conversation>) beans.iterator().next();
+ CreationalContext<Conversation> creationalContext = beanManager.createCreationalContext(conversationBean);
+ Conversation conversation =
+ (Conversation) beanManager.getReference(conversationBean, Conversation.class, creationalContext);
+
+ return conversation;
+ }
+}
Propchange: incubator/openwebbeans/trunk/webbeans-jsf/src/main/java/org/apache/webbeans/jsf/ConversationAwareViewHandler.java
------------------------------------------------------------------------------
svn:eol-style = native