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 2010/03/04 13:25:07 UTC

svn commit: r918964 - in /myfaces/extensions/cdi/branches/branch_for_jsf_1_2: examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/ examples/hello_myfaces-codi/src/main/webapp/ jee-modules/jsf-module/src/main/java/org/apache/myfaces/exten...

Author: gpetracek
Date: Thu Mar  4 12:25:07 2010
New Revision: 918964

URL: http://svn.apache.org/viewvc?rev=918964&view=rev
Log:
EXTCDI-11 small addition

Added:
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/FacesInformationProvider.java
Modified:
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/HelloCodiBean.java
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/webapp/helloMyFacesCodi.jsp
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/PhaseId.java
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/AfterPhase.java
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/BeforePhase.java
    myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/JsfRequestLifecycleBroadcaster.java

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/HelloCodiBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/HelloCodiBean.java?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/HelloCodiBean.java (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/java/org/apache/myfaces/blank/HelloCodiBean.java Thu Mar  4 12:25:07 2010
@@ -26,6 +26,8 @@
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Model;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.inject.Inject;
 
@@ -35,13 +37,15 @@
     @Inject
     private JsfProjectStage jsfProjectStage;
 
+    @Inject
+    private FacesContext facesContext;
+
     private String text;
-    private StringBuffer invokedListenerMethods = new StringBuffer();
 
+    //no restriction via @View -> invoked before rendering any view
     public void preRenderView(@Observes @BeforePhase(PhaseId.RENDER_RESPONSE) PhaseEvent event)
     {
-        this.invokedListenerMethods.append("preRenderView in phase:").append(event.getPhaseId());
-        this.invokedListenerMethods.append(" | ");
+        addGlobalMessage("preRenderView in phase:" + event.getPhaseId());
 
         this.text = "Hello MyFaces CODI";
     }
@@ -49,22 +53,34 @@
     @View("/helloMyFacesCodi.jsp")
     public void preInvokeApplication(@Observes @BeforePhase(PhaseId.INVOKE_APPLICATION) PhaseEvent event)
     {
-        this.invokedListenerMethods.append("preInvokeApplication in phase:").append(event.getPhaseId());
-        this.invokedListenerMethods.append(" | ");
+        addGlobalMessage("preInvokeApplication in phase:" + event.getPhaseId());
     }
 
     @View("/invalidPage.jsp")
     public void postRestoreViewInvalid(@Observes @AfterPhase(PhaseId.RESTORE_VIEW) PhaseEvent event)
     {
-        this.invokedListenerMethods.append("postRestoreViewInvalid in phase:").append(event.getPhaseId());
-        this.invokedListenerMethods.append(" | ");
+        addGlobalMessage("postRestoreViewInvalid in phase:" + event.getPhaseId());
     }
 
     @View({"/invalidPage.jsp", "/helloMyFacesCodi.jsp"})
     public void postRestoreView(@Observes @AfterPhase(PhaseId.RESTORE_VIEW) PhaseEvent event)
     {
-        this.invokedListenerMethods.append("postRestoreView in phase:").append(event.getPhaseId());
-        this.invokedListenerMethods.append(" | ");
+        addGlobalMessage("postRestoreView in phase:" + event.getPhaseId());
+    }
+
+    //no restriction via @View -> invoked for any view
+    public void preAny(@Observes @BeforePhase(PhaseId.ANY_PHASE) PhaseEvent event)
+    {
+        addGlobalMessage("preAny in phase:" + event.getPhaseId());
+    }
+
+    public void preAnyFiltered(@Observes @BeforePhase(PhaseId.ANY_PHASE) PhaseEvent event)
+    {
+        if (event.getPhaseId().equals(javax.faces.event.PhaseId.APPLY_REQUEST_VALUES) ||
+                event.getPhaseId().equals(javax.faces.event.PhaseId.UPDATE_MODEL_VALUES))
+        {
+            addGlobalMessage("preAnyFiltered in phase:" + event.getPhaseId());
+        }
     }
 
     public String getText()
@@ -77,8 +93,8 @@
         return this.jsfProjectStage.toString();
     }
 
-    public String getInvokedListenerMethods()
+    private void addGlobalMessage(String messageText)
     {
-        return invokedListenerMethods.toString();
+        this.facesContext.addMessage(null, new FacesMessage(messageText));
     }
 }

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/webapp/helloMyFacesCodi.jsp
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/webapp/helloMyFacesCodi.jsp?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/webapp/helloMyFacesCodi.jsp (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/examples/hello_myfaces-codi/src/main/webapp/helloMyFacesCodi.jsp Thu Mar  4 12:25:07 2010
@@ -31,11 +31,9 @@
                     <h:outputLabel for="txtProjctStage" value="Project stage:"/>
                     <h:outputText id="txtProjctStage" value="#{helloCodiBean.projectStageName}"/>
 
-                    <h:outputLabel for="txtInvokedListenerMethods" value="Invoked:"/>
-                    <h:outputText id="txtInvokedListenerMethods" value="#{helloCodiBean.invokedListenerMethods}"/>
-
                     <h:commandButton value="send"/>
                 </h:panelGrid>
+                <h:messages globalOnly="true"/>
             </h:form>
         </f:view>
     </body>

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/PhaseId.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/PhaseId.java?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/PhaseId.java (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/PhaseId.java Thu Mar  4 12:25:07 2010
@@ -25,7 +25,8 @@
     PROCESS_VALIDATIONS(javax.faces.event.PhaseId.PROCESS_VALIDATIONS),
     UPDATE_MODEL_VALUES(javax.faces.event.PhaseId.UPDATE_MODEL_VALUES),
     INVOKE_APPLICATION(javax.faces.event.PhaseId.INVOKE_APPLICATION),
-    RENDER_RESPONSE(javax.faces.event.PhaseId.RENDER_RESPONSE);
+    RENDER_RESPONSE(javax.faces.event.PhaseId.RENDER_RESPONSE),
+    ANY_PHASE(javax.faces.event.PhaseId.ANY_PHASE);
 
     javax.faces.event.PhaseId phaseId;
 
@@ -34,7 +35,12 @@
         this.phaseId = phaseId;
     }
 
-    public static PhaseId convert(javax.faces.event.PhaseId phaseId)
+    public static javax.faces.event.PhaseId convertToFacesClass(PhaseId phaseId)
+    {
+        return phaseId.getPhaseId();
+    }
+
+    public static PhaseId convertFromFacesClass(javax.faces.event.PhaseId phaseId)
     {
         if(RESTORE_VIEW.getPhaseId().equals(phaseId))
         {

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/AfterPhase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/AfterPhase.java?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/AfterPhase.java (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/AfterPhase.java Thu Mar  4 12:25:07 2010
@@ -23,11 +23,12 @@
 import javax.inject.Qualifier;
 import java.lang.annotation.Documented;
 import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
 import java.lang.annotation.Retention;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 import java.lang.annotation.Target;
 
-@Target(PARAMETER)
+@Target({PARAMETER, FIELD})
 @Retention(RUNTIME)
 @Documented
 

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/BeforePhase.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/BeforePhase.java?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/BeforePhase.java (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/api/listener/phase/annotation/BeforePhase.java Thu Mar  4 12:25:07 2010
@@ -23,11 +23,12 @@
 import javax.inject.Qualifier;
 import java.lang.annotation.Documented;
 import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
 import java.lang.annotation.Retention;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 import java.lang.annotation.Target;
 
-@Target(PARAMETER)
+@Target({PARAMETER, FIELD})
 @Retention(RUNTIME)
 @Documented
 

Added: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/FacesInformationProvider.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/FacesInformationProvider.java?rev=918964&view=auto
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/FacesInformationProvider.java (added)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/FacesInformationProvider.java Thu Mar  4 12:25:07 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.javaee.jsf.impl.listener.phase;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.faces.context.FacesContext;
+
+@RequestScoped
+public class FacesInformationProvider
+{
+    @Produces
+    @RequestScoped
+    protected FacesContext currentFacesContext()
+    {
+        return FacesContext.getCurrentInstance();
+    }
+}

Modified: myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/JsfRequestLifecycleBroadcaster.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/JsfRequestLifecycleBroadcaster.java?rev=918964&r1=918963&r2=918964&view=diff
==============================================================================
--- myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/JsfRequestLifecycleBroadcaster.java (original)
+++ myfaces/extensions/cdi/branches/branch_for_jsf_1_2/jee-modules/jsf-module/src/main/java/org/apache/myfaces/extensions/cdi/javaee/jsf/impl/listener/phase/JsfRequestLifecycleBroadcaster.java Thu Mar  4 12:25:07 2010
@@ -19,6 +19,8 @@
 package org.apache.myfaces.extensions.cdi.javaee.jsf.impl.listener.phase;
 
 import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.PhaseId;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.annotation.AfterPhase;
+import org.apache.myfaces.extensions.cdi.javaee.jsf.api.listener.phase.annotation.BeforePhase;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Event;
@@ -36,19 +38,29 @@
     @Inject
     private Event<PhaseEvent> phaseEvent;
 
+    @Inject
+    @BeforePhase(PhaseId.ANY_PHASE)
+    private Event<PhaseEvent> beforeAnyPhaseEvent;
+
+    @Inject
+    @AfterPhase(PhaseId.ANY_PHASE)
+    private Event<PhaseEvent> afterAnyPhaseEvent;
+
     void broadcastBeforeEvent(PhaseEvent phaseEvent)
     {
         this.phaseEvent.select(createAnnotationLiteral(phaseEvent.getPhaseId(), true)).fire(phaseEvent);
+        this.beforeAnyPhaseEvent.fire(phaseEvent);
     }
 
     void broadcastAfterEvent(PhaseEvent phaseEvent)
     {
         this.phaseEvent.select(createAnnotationLiteral(phaseEvent.getPhaseId(), false)).fire(phaseEvent);
+        this.afterAnyPhaseEvent.fire(phaseEvent);
     }
 
     private Annotation createAnnotationLiteral(javax.faces.event.PhaseId phaseId, boolean isBeforeEvent)
     {
-        if(isBeforeEvent)
+        if (isBeforeEvent)
         {
             return createBeforeLiteral(phaseId);
         }
@@ -57,24 +69,26 @@
 
     private Annotation createBeforeLiteral(final javax.faces.event.PhaseId phaseId)
     {
-        return new BeforePhaseBinding() {
+        return new BeforePhaseBinding()
+        {
             private static final long serialVersionUID = 849645435335842723L;
 
             public PhaseId value()
             {
-                return PhaseId.convert(phaseId);
+                return PhaseId.convertFromFacesClass(phaseId);
             }
         };
     }
 
     private Annotation createAfterLiteral(final javax.faces.event.PhaseId phaseId)
     {
-        return new AfterPhaseBinding() {
+        return new AfterPhaseBinding()
+        {
             private static final long serialVersionUID = 490037768660184656L;
 
             public PhaseId value()
             {
-                return PhaseId.convert(phaseId);
+                return PhaseId.convertFromFacesClass(phaseId);
             }
         };
     }