You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2011/04/16 23:37:02 UTC
svn commit: r1094058 - in
/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module:
api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/
impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/
impl/src/main/java/org/apache...
Author: gpetracek
Date: Sat Apr 16 21:37:02 2011
New Revision: 1094058
URL: http://svn.apache.org/viewvc?rev=1094058&view=rev
Log:
EXTCDI-167 workaround for PreDestroyViewMapEvent which would be caused by the security check
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/TemporaryComponent.java
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/TemporaryUIViewRoot.java
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/TemporaryViewRootAwareApplicationWrapper.java
Modified:
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/TemporaryComponent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/TemporaryComponent.java?rev=1094058&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/TemporaryComponent.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/api/view/TemporaryComponent.java Sat Apr 16 21:37:02 2011
@@ -0,0 +1,31 @@
+/*
+ * 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.extensions.cdi.jsf2.api.view;
+
+/**
+ * @author Gerhard Petracek
+ */
+public interface TemporaryComponent
+{
+ /**
+ * De-/activates the temporary-mode
+ * @param activateTemporaryMode true to activate it, false otherwise
+ */
+ void setTemporaryMode(boolean activateTemporaryMode);
+}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/TemporaryUIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/TemporaryUIViewRoot.java?rev=1094058&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/TemporaryUIViewRoot.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/component/TemporaryUIViewRoot.java Sat Apr 16 21:37:02 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.extensions.cdi.jsf2.impl.component;
+
+import org.apache.myfaces.extensions.cdi.jsf2.api.view.TemporaryComponent;
+
+import javax.faces.component.UIViewRoot;
+
+//needed due to EXTCDI-167
+/**
+ * @author Gerhard Petracek
+ */
+public class TemporaryUIViewRoot extends UIViewRoot implements TemporaryComponent
+{
+ private boolean activateTemporaryMode;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setTemporaryMode(boolean activateTemporaryMode)
+ {
+ this.activateTemporaryMode = activateTemporaryMode;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ //noinspection SimplifiableIfStatement
+ if(this.activateTemporaryMode)
+ {
+ //workaround for PreDestroyViewMapEvent which would be caused by the security check
+ return true;
+ }
+ return super.equals(obj);
+ }
+
+ //needed due to checkstyle rules
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ return super.hashCode();
+ }
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java?rev=1094058&r1=1094057&r2=1094058&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java Sat Apr 16 21:37:02 2011
@@ -24,6 +24,7 @@ import org.apache.myfaces.extensions.cdi
import org.apache.myfaces.extensions.cdi.jsf.impl.listener.request.BeforeAfterFacesRequestBroadcaster;
import org.apache.myfaces.extensions.cdi.jsf.impl.listener.request.FacesMessageEntry;
import org.apache.myfaces.extensions.cdi.jsf2.impl.scope.conversation.RedirectedConversationAwareExternalContext;
+import org.apache.myfaces.extensions.cdi.jsf2.impl.security.SecurityAwareViewHandler;
import org.apache.myfaces.extensions.cdi.message.api.Message;
import javax.faces.application.FacesMessage;
@@ -48,6 +49,8 @@ class CodiFacesContextWrapper extends Fa
private BeforeAfterFacesRequestBroadcaster beforeAfterFacesRequestBroadcaster;
+ private boolean temporaryViewRootAwareApplicationWrapperActivated;
+
CodiFacesContextWrapper(FacesContext wrappedFacesContext)
{
this.wrappedFacesContext = wrappedFacesContext;
@@ -66,8 +69,14 @@ class CodiFacesContextWrapper extends Fa
public Application getApplication()
{
lazyInit();
- return new InjectionAwareApplicationWrapper(wrappedFacesContext.getApplication(),
+ Application application = new InjectionAwareApplicationWrapper(wrappedFacesContext.getApplication(),
this.advancedQualifierRequiredForDependencyInjection);
+
+ if(this.temporaryViewRootAwareApplicationWrapperActivated)
+ {
+ return new TemporaryViewRootAwareApplicationWrapper(application);
+ }
+ return application;
}
/**
@@ -109,6 +118,10 @@ class CodiFacesContextWrapper extends Fa
this.beforeAfterFacesRequestBroadcaster =
CodiUtils.getContextualReferenceByClass(BeforeAfterFacesRequestBroadcaster.class);
+
+ this.temporaryViewRootAwareApplicationWrapperActivated =
+ ClassDeactivation.isClassActivated(SecurityAwareViewHandler.class) &&
+ ClassDeactivation.isClassActivated(TemporaryViewRootAwareApplicationWrapper.class);
}
}
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/TemporaryViewRootAwareApplicationWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/TemporaryViewRootAwareApplicationWrapper.java?rev=1094058&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/TemporaryViewRootAwareApplicationWrapper.java (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/TemporaryViewRootAwareApplicationWrapper.java Sat Apr 16 21:37:02 2011
@@ -0,0 +1,136 @@
+/*
+ * 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.extensions.cdi.jsf2.impl.listener.request;
+
+import org.apache.myfaces.extensions.cdi.jsf2.impl.component.TemporaryUIViewRoot;
+
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationWrapper;
+import javax.faces.application.Resource;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+//needed due to EXTCDI-167
+/**
+ * @author Gerhard Petracek
+ */
+class TemporaryViewRootAwareApplicationWrapper extends ApplicationWrapper
+{
+ private Application wrapped;
+
+ TemporaryViewRootAwareApplicationWrapper(Application wrapped)
+ {
+ this.wrapped = wrapped;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Application getWrapped()
+ {
+ return this.wrapped;
+ }
+
+ protected UIComponent tryToWrapUIViewRoot(UIComponent uiComponent)
+ {
+ if(uiComponent instanceof UIViewRoot)
+ {
+ if(!uiComponent.getClass().getName().equals(UIViewRoot.class.getName()))
+ {
+ return getCustomizedUIViewRoot(uiComponent);
+ }
+ return new TemporaryUIViewRoot();
+ }
+ return uiComponent;
+ }
+
+ private UIComponent getCustomizedUIViewRoot(UIComponent uiComponent)
+ {
+ //TODO proxy or custom (optional) factory
+ return uiComponent;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(FacesContext context,
+ Resource componentResource)
+ {
+ return tryToWrapUIViewRoot(super.createComponent(context, componentResource));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(FacesContext context,
+ String componentType,
+ String rendererType)
+ {
+ return tryToWrapUIViewRoot(super.createComponent(context, componentType, rendererType));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(String componentType) throws FacesException
+ {
+ return tryToWrapUIViewRoot(super.createComponent(componentType));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(ValueBinding componentBinding,
+ FacesContext context,
+ String componentType) throws FacesException
+ {
+ return tryToWrapUIViewRoot(super.createComponent(componentBinding, context, componentType));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(ValueExpression componentExpression,
+ FacesContext context,
+ String componentType,
+ String rendererType)
+ {
+ return tryToWrapUIViewRoot(super.createComponent(componentExpression, context, componentType, rendererType));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UIComponent createComponent(ValueExpression componentExpression,
+ FacesContext contexte,
+ String componentType) throws FacesException
+ {
+ return tryToWrapUIViewRoot(super.createComponent(componentExpression, contexte, componentType));
+ }
+}
Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java?rev=1094058&r1=1094057&r2=1094058&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/security/SecurityAwareViewHandler.java Sat Apr 16 21:37:02 2011
@@ -18,6 +18,8 @@
*/
package org.apache.myfaces.extensions.cdi.jsf2.impl.security;
+import org.apache.myfaces.extensions.cdi.jsf2.api.view.TemporaryComponent;
+
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
@@ -61,8 +63,19 @@ public class SecurityAwareViewHandler
}
}
+ if(originalViewRoot instanceof TemporaryComponent)
+ {
+ //workaround for PreDestroyViewMapEvent which would be caused by the security check
+ ((TemporaryComponent)originalViewRoot).setTemporaryMode(true);
+ }
+
newViewRoot = super.createView(context, viewId);
+ if(originalViewRoot instanceof TemporaryComponent)
+ {
+ ((TemporaryComponent)originalViewRoot).setTemporaryMode(false);
+ }
+
if(viewMap != null)
{
originalViewRoot.getViewMap(true).putAll(viewMap);