Author: svieujot
Date: Sat May  7 14:20:15 2005
New Revision: 169110

URL: http://svn.apache.org/viewcvs?rev=169110&view=rev
Log:
Add aliasBeansScope tag.

Added:
    myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java 
  (with props)
    
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java
   (with props)
    
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java
   (with props)
    
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java
   (with props)
    
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java
   (with props)
Modified:
    myfaces/trunk/conf/faces-config.xml
    myfaces/trunk/doc/release-notes.txt
    
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java
    myfaces/trunk/tlds/myfaces_ext.tld
    myfaces/trunk/webapps/simple/WEB-INF/examples-config.xml
    myfaces/trunk/webapps/simple/aliasBean.jsp

Modified: myfaces/trunk/conf/faces-config.xml
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/conf/faces-config.xml?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
--- myfaces/trunk/conf/faces-config.xml (original)
+++ myfaces/trunk/conf/faces-config.xml Sat May  7 14:20:15 2005
@@ -104,6 +104,11 @@
     <component-type>org.apache.myfaces.AliasBean</component-type>
     
<component-class>org.apache.myfaces.custom.aliasbean.AliasBean</component-class>
   </component>
+  
+  <component>
+    <component-type>org.apache.myfaces.AliasBeansScope</component-type>
+    
<component-class>org.apache.myfaces.custom.aliasbean.AliasBeansScope</component-class>
+  </component>
 
   <component>
     <component-type>org.apache.myfaces.Buffer</component-type>
@@ -398,6 +403,12 @@
             <component-family>javax.faces.Data</component-family>
             <renderer-type>org.apache.myfaces.AliasBean</renderer-type>
             
<renderer-class>org.apache.myfaces.custom.aliasbean.AliasBeanRenderer</renderer-class>
+        </renderer>
+        
+        <renderer>
+            <component-family>javax.faces.Data</component-family>
+            <renderer-type>org.apache.myfaces.AliasBeansScope</renderer-type>
+            
<renderer-class>org.apache.myfaces.custom.aliasbean.AliasBeansScopeRenderer</renderer-class>
         </renderer>
 
         <renderer>

Modified: myfaces/trunk/doc/release-notes.txt
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/doc/release-notes.txt?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
--- myfaces/trunk/doc/release-notes.txt (original)
+++ myfaces/trunk/doc/release-notes.txt Sat May  7 14:20:15 2005
@@ -5,6 +5,7 @@
 Changes in Release 1.0.10
 * added renderFacetsIfSinglePage to x:dataScroller
 * aliasBean : avoid evaluating expressions on each phase
+* added aliasBeansScope tag to make configuration with multiple aliasBean 
easier to manage.
 * closed MYFACES-177
 * closed MYFACES-199
 * closed MYFACES-209

Added: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java?rev=169110&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java 
(added)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java 
Sat May  7 14:20:15 2005
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.myfaces.custom.aliasbean;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * $Log$
+ */
+
+class Alias {
+    static final Log log = LogFactory.getLog(Alias.class);
+       
+       private transient UIComponent _aliasComponent;
+       private String _aliasBeanExpression;
+    private String _valueExpression;
+       private transient boolean _active = false;
+       
+       private transient Object evaluatedExpression = null;
+
+       Alias(AliasBean aliasComponent){
+               this._aliasComponent = aliasComponent;
+       }
+       
+       void setAliasBeanExpression(String aliasBeanExpression){
+               this._aliasBeanExpression = aliasBeanExpression;
+       }
+       
+       void setValueExpression(String valueExpression){
+               this._valueExpression = valueExpression;
+       }
+       
+       String getValueExpression(){
+               return _valueExpression;
+       }
+       
+       boolean isActive(){
+               return _active;
+       }
+       
+       String[] saveState(){
+               return new String[]{_aliasBeanExpression, _valueExpression};
+       }
+       
+       void restoreState(Object state){
+               String[] values = (String[]) state;
+               _aliasBeanExpression = values[0];
+               _valueExpression = values[1];
+       }
+       
+       private void computeEvaluatedExpression(FacesContext facesContext){
+               if( evaluatedExpression != null )
+                       return;
+               
+               ValueBinding valueVB = null;
+        if (_valueExpression == null) {
+            valueVB = _aliasComponent.getValueBinding("value");
+            _valueExpression = valueVB.getExpressionString();
+        }
+
+        if( valueVB == null ){
+            if( _valueExpression.startsWith("#{") ){
+                valueVB = 
facesContext.getApplication().createValueBinding(_valueExpression);
+                               evaluatedExpression = 
valueVB.getValue(facesContext);
+            }else{
+                               evaluatedExpression = _valueExpression;
+            }
+        }else{
+                       evaluatedExpression = valueVB.getValue(facesContext);
+        }
+       }
+       
+       void make(FacesContext facesContext){
+               if( _active )
+                       return;
+
+        ValueBinding aliasVB;
+        if (_aliasBeanExpression == null) {
+            aliasVB = _aliasComponent.getValueBinding("alias");
+                       if( aliasVB == null )
+                               return;
+            _aliasBeanExpression = aliasVB.getExpressionString();
+                       if( _aliasBeanExpression == null )
+                               return;
+        } else {
+            aliasVB = 
facesContext.getApplication().createValueBinding(_aliasBeanExpression);
+        }
+
+               computeEvaluatedExpression( facesContext );
+               
+        aliasVB.setValue(facesContext, evaluatedExpression);
+               _active = true;
+
+        log.debug("makeAlias: " + _valueExpression + " = " + 
_aliasBeanExpression);
+       }
+       
+       void remove(FacesContext facesContext){
+               if( evaluatedExpression == null )
+                       return;
+
+        log.debug("removeAlias: " + _valueExpression + " != " + 
_aliasBeanExpression);
+        ValueBinding aliasVB = _aliasComponent.getValueBinding("alias");
+        if( aliasVB != null )
+                       aliasVB.setValue(facesContext, null);
+               _active = false;
+       }
+}
\ No newline at end of file

Propchange: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/Alias.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
--- 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java 
(original)
+++ 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java 
Sat May  7 14:20:15 2005
@@ -27,8 +27,6 @@
 import javax.faces.el.ValueBinding;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-import javax.faces.event.PhaseId;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -85,15 +83,15 @@
     public static final String COMPONENT_FAMILY = "javax.faces.Data";
     private static final String DEFAULT_RENDERER_TYPE = 
"org.apache.myfaces.AliasBean";
 
-    private String _valueExpression = null;
-
-    private String _aliasBeanExpression = null;
+    private Alias alias;
+       private boolean scopeSearched = false;
+       private boolean withinScope;
 
     private transient FacesContext _context = null;
-       private transient Object evaluatedExpression = null;
 
     public AliasBean() {
         setRendererType(DEFAULT_RENDERER_TYPE);
+               alias = new Alias( this );
     }
 
     public String getFamily() {
@@ -101,17 +99,18 @@
     }
 
     public void setAlias(String aliasBeanExpression){
-        this._aliasBeanExpression = aliasBeanExpression;
+        alias.setAliasBeanExpression( aliasBeanExpression );
     }
     
     public String getValue(){
-        if (_valueExpression != null)
-            return _valueExpression;
+               String valueExpression = alias.getValueExpression(); 
+        if (valueExpression != null)
+            return valueExpression;
         ValueBinding vb = getValueBinding("value");
         return vb != null ? (String)vb.getValue(getFacesContext()) : null;
     }
     public void setValue(String valueExpression){
-        this._valueExpression = valueExpression;
+        alias.setValueExpression( valueExpression );
     }
 
     public Object saveState(FacesContext context) {
@@ -119,11 +118,8 @@
 
         _context = context;
 
-        Object values[] = new Object[3];
-        values[0] = super.saveState(context);
-        values[1] = _valueExpression;
-        values[2] = _aliasBeanExpression;
-        return values;
+               Object[] state = {super.saveState(context), alias.saveState()};
+               return state;
     }
 
     public void restoreState(FacesContext context, Object state) {
@@ -133,8 +129,7 @@
 
         Object values[] = (Object[]) state;
         super.restoreState(context, values[0]);
-        _valueExpression = (String) values[1];
-        _aliasBeanExpression = (String) values[2];
+               alias.restoreState(values[1]);
     }
 
     public Object processSaveState(FacesContext context) {
@@ -208,6 +203,9 @@
     }
 
     public void processValidators(FacesContext context) {
+               if( withinScope )
+                       return;
+
         log.debug("processValidators");
         makeAlias(context);
         super.processValidators(context);
@@ -216,12 +214,23 @@
 
        public void processDecodes(FacesContext context) {
                log.debug("processDecodes");
+               if( withinScope ){
+                       if( ! alias.isActive() )
+                               makeAlias(context);
+
+                       super.processDecodes(context);
+                       return;
+               }
+
                makeAlias(context);
                super.processDecodes(context);
                removeAlias(context);
        }
        
     public void processUpdates(FacesContext context) {
+               if( withinScope )
+                       return;
+
         log.debug("processUpdates");
         makeAlias(context);
         super.processUpdates(context);
@@ -249,45 +258,17 @@
         _context = context;
         makeAlias();
     }
-       
-       private void computeEvaluatedExpression(){
-               if( evaluatedExpression != null )
-                       return;
-               
-               ValueBinding valueVB = null;
-        if (_valueExpression == null) {
-            valueVB = getValueBinding("value");
-            _valueExpression = valueVB.getExpressionString();
-        }
-
-        if( valueVB == null ){
-            if( _valueExpression.startsWith("#{") ){
-                valueVB = 
_context.getApplication().createValueBinding(_valueExpression);
-                               evaluatedExpression = 
valueVB.getValue(_context);
-            }else{
-                               evaluatedExpression = _valueExpression;
-            }
-        }else{
-                       evaluatedExpression = valueVB.getValue(_context);
-        }
-       }
 
     private void makeAlias() {
-        // First, compute the value or reference
-               computeEvaluatedExpression();
-
-        // Then set the alias to this value
-        ValueBinding aliasVB;
-        if (_aliasBeanExpression == null) {
-            aliasVB = getValueBinding("alias");
-            _aliasBeanExpression = aliasVB.getExpressionString();
-        } else {
-            aliasVB = 
_context.getApplication().createValueBinding(_aliasBeanExpression);
-        }
-
-        aliasVB.setValue(_context, evaluatedExpression);
-
-        log.debug("makeAlias: " + _valueExpression + " = " + 
_aliasBeanExpression);
+               if( ! scopeSearched ){
+                       withinScope =  getParent() instanceof AliasBeansScope;
+                       if( withinScope ){
+                               AliasBeansScope aliasScope = (AliasBeansScope) 
getParent();
+                               aliasScope.addAlias( alias );
+                       }
+                       scopeSearched = true;
+               }
+               alias.make( _context );
     }
 
     void removeAlias(FacesContext context) {
@@ -296,46 +277,7 @@
     }
 
     private void removeAlias() {
-        log.debug("removeAlias: " + _valueExpression + " != " + 
_aliasBeanExpression);
-
-        ValueBinding aliasVB = getValueBinding("alias");
-        aliasVB.setValue(_context, null);
-    }
-
-    private static class FacesEventWrapper extends FacesEvent {
-        private FacesEvent _wrappedFacesEvent;
-
-        public FacesEventWrapper(FacesEvent facesEvent, AliasBean 
redirectComponent) {
-            super(redirectComponent);
-            _wrappedFacesEvent = facesEvent;
-        }
-
-        public PhaseId getPhaseId() {
-            return _wrappedFacesEvent.getPhaseId();
-        }
-
-        public void setPhaseId(PhaseId phaseId) {
-            _wrappedFacesEvent.setPhaseId(phaseId);
-        }
-
-        public void queue() {
-            _wrappedFacesEvent.queue();
-        }
-
-        public String toString() {
-            return _wrappedFacesEvent.toString();
-        }
-
-        public boolean isAppropriateListener(FacesListener faceslistener) {
-            return _wrappedFacesEvent.isAppropriateListener(faceslistener);
-        }
-
-        public void processListener(FacesListener faceslistener) {
-            _wrappedFacesEvent.processListener(faceslistener);
-        }
-
-        public FacesEvent getWrappedFacesEvent() {
-            return _wrappedFacesEvent;
-        }
+        if( ! withinScope )
+                       alias.remove( _context );
     }
 }

Added: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java?rev=169110&view=auto
==============================================================================
--- 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java
 (added)
+++ 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java
 Sat May  7 14:20:15 2005
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.myfaces.custom.aliasbean;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Holds several aliases that are configured by aliasBean tags.
+ * 
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * $Log$
+ */
+public class AliasBeansScope extends UIComponentBase {
+    static final Log log = LogFactory.getLog(AliasBeansScope.class);
+
+    public static final String COMPONENT_TYPE = 
"org.apache.myfaces.AliasBeansScope";
+    public static final String COMPONENT_FAMILY = "javax.faces.Data";
+    private static final String DEFAULT_RENDERER_TYPE = 
"org.apache.myfaces.AliasBeansScope";
+
+       private ArrayList _aliases = new ArrayList();
+    transient FacesContext _context = null;
+
+    public AliasBeansScope() {
+        setRendererType(DEFAULT_RENDERER_TYPE);
+    }
+       
+       void addAlias(Alias alias){
+               _aliases.add( alias );
+       }
+
+    public String getFamily() {
+        return COMPONENT_FAMILY;
+    }
+
+    public Object saveState(FacesContext context) {
+        log.debug("saveState");
+        _context = context;
+
+        return super.saveState(context);
+    }
+
+    public void restoreState(FacesContext context, Object state) {
+        log.debug("restoreState");
+        _context = context;
+
+        super.restoreState(context, state);
+    }
+
+    public Object processSaveState(FacesContext context) {
+        if (context == null)
+            throw new NullPointerException("context");
+        if (isTransient())
+            return null;
+               
+        Map facetMap = null;
+        for (Iterator it = getFacets().entrySet().iterator(); it.hasNext();) {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (facetMap == null)
+                facetMap = new HashMap();
+            UIComponent component = (UIComponent) entry.getValue();
+            if (!component.isTransient()) {
+                facetMap.put(entry.getKey(), 
component.processSaveState(context));
+            }
+        }
+               
+               makeAliases(context);
+               
+        List childrenList = null;
+        if (getChildCount() > 0) {
+            for (Iterator it = getChildren().iterator(); it.hasNext();) {
+                UIComponent child = (UIComponent) it.next();
+                if (!child.isTransient()) {
+                    if (childrenList == null)
+                        childrenList = new ArrayList(getChildCount());
+                    childrenList.add(child.processSaveState(context));
+                }
+            }
+        }
+               
+               removeAliases(context);
+               
+        return new Object[] { saveState(context), facetMap, childrenList };
+    }
+
+    public void processRestoreState(FacesContext context, Object state) {
+        if (context == null)
+            throw new NullPointerException("context");
+        Object myState = ((Object[]) state)[0];
+
+        restoreState(context, myState);
+        makeAliases(context);
+
+        Map facetMap = (Map) ((Object[]) state)[1];
+        
+        for (Iterator it = getFacets().entrySet().iterator(); it.hasNext();) {
+            Map.Entry entry = (Map.Entry) it.next();
+            Object facetState = facetMap.get(entry.getKey());
+            if (facetState != null) {
+                ((UIComponent) entry.getValue()).processRestoreState(context, 
facetState);
+            } else {
+                context.getExternalContext().log("No state found to restore 
facet " + entry.getKey());
+            }
+        }
+               
+               List childrenList = (List) ((Object[]) state)[2];
+        if (getChildCount() > 0) {
+            int idx = 0;
+            for (Iterator it = getChildren().iterator(); it.hasNext();) {
+                UIComponent child = (UIComponent) it.next();
+                Object childState = childrenList.get(idx++);
+                if (childState != null) {
+                    child.processRestoreState(context, childState);
+                } else {
+                    context.getExternalContext().log("No state found to 
restore child of component " + getId());
+                }
+            }
+        }
+
+        removeAliases(context);
+    }
+
+    public void processValidators(FacesContext context) {
+        log.debug("processValidators");
+        makeAliases(context);
+        super.processValidators(context);
+        removeAliases(context);
+    }
+
+       public void processDecodes(FacesContext context) {
+               log.debug("processDecodes");
+               makeAliases(context);
+               super.processDecodes(context);
+               removeAliases(context);
+       }
+       
+    public void processUpdates(FacesContext context) {
+        log.debug("processUpdates");
+        makeAliases(context);
+        super.processUpdates(context);
+        removeAliases(context);
+    }
+
+    public void queueEvent(FacesEvent event) {
+               super.queueEvent(new FacesEventWrapper(event, this));
+    }
+
+    public void broadcast(FacesEvent event) throws AbortProcessingException {
+        makeAliases();
+
+        if (event instanceof FacesEventWrapper) {
+            FacesEvent originalEvent = ((FacesEventWrapper) 
event).getWrappedFacesEvent();
+            originalEvent.getComponent().broadcast(originalEvent);
+        } else {
+            super.broadcast(event);
+        }
+
+        removeAliases();
+       }
+       
+    void makeAliases(FacesContext context) {
+        _context = context;
+               makeAliases();
+    }
+
+    private void makeAliases() {
+               for(Iterator i = _aliases.iterator() ; i.hasNext() ;)
+                       ((Alias)i.next()).make( _context );
+    }
+
+    void removeAliases(FacesContext context) {
+        _context = context;
+        removeAliases();
+    }
+
+    private void removeAliases() {
+               for(Iterator i = _aliases.iterator() ; i.hasNext() ;)
+                       ((Alias)i.next()).remove( _context );
+    }
+}
\ No newline at end of file

Propchange: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScope.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java?rev=169110&view=auto
==============================================================================
--- 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java
 (added)
+++ 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java
 Sat May  7 14:20:15 2005
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.myfaces.custom.aliasbean;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * $Log$
+ *
+ */
+public class AliasBeansScopeRenderer extends Renderer {
+    private static final Log log = 
LogFactory.getLog(AliasBeansScopeRenderer.class);
+
+    public void encodeBegin(FacesContext facesContext, UIComponent 
uiComponent) {
+        log.debug("encodeBegin");
+
+        AliasBeansScope aliasBeansScope = (AliasBeansScope) uiComponent;
+               aliasBeansScope.makeAliases(facesContext);
+    }
+       
+    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) {
+        log.debug("encodeEnd");
+
+               AliasBeansScope aliasBeansScope = (AliasBeansScope) uiComponent;
+               aliasBeansScope.removeAliases(facesContext);
+    }
+}
\ No newline at end of file

Propchange: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeRenderer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java?rev=169110&view=auto
==============================================================================
--- 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java
 (added)
+++ 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java
 Sat May  7 14:20:15 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.myfaces.custom.aliasbean;
+
+import org.apache.myfaces.taglib.UIComponentTagBase;
+
+/**
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * $Log$
+ */
+public class AliasBeansScopeTag extends UIComponentTagBase {
+    
+    public String getComponentType() {
+        return AliasBeansScope.COMPONENT_TYPE;
+    }
+
+    public String getRendererType() {
+        return null;
+    }
+    
+}
\ No newline at end of file

Propchange: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/AliasBeansScopeTag.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java?rev=169110&view=auto
==============================================================================
--- 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java
 (added)
+++ 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java
 Sat May  7 14:20:15 2005
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.myfaces.custom.aliasbean;
+
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.event.PhaseId;
+
+/**
+ * The aliasBean tag allows you to link a fictive bean to a real bean.
+ * 
+ * Let's suppose you have a subform you use often but with different beans.
+ * <br/>The aliasBean allows you to design the subform with a fictive bean and
+ * to include it in all the pages where you use it. You just need to make an
+ * alias to the real bean named after the fictive bean before invoking the
+ * fictive bean. <br/>This making it possible to have a library of reusable
+ * generic subforms.
+ * 
+ * @author Sylvain Vieujot (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * $Log$
+ */
+
+class FacesEventWrapper extends FacesEvent {
+    private FacesEvent _wrappedFacesEvent;
+
+    public FacesEventWrapper(FacesEvent facesEvent, AliasBeansScope 
redirectComponent) {
+        super(redirectComponent);
+        _wrappedFacesEvent = facesEvent;
+    }
+       
+    public FacesEventWrapper(FacesEvent facesEvent, AliasBean 
redirectComponent) {
+        super(redirectComponent);
+        _wrappedFacesEvent = facesEvent;
+    }
+
+    public PhaseId getPhaseId() {
+        return _wrappedFacesEvent.getPhaseId();
+    }
+
+    public void setPhaseId(PhaseId phaseId) {
+        _wrappedFacesEvent.setPhaseId(phaseId);
+    }
+
+    public void queue() {
+        _wrappedFacesEvent.queue();
+    }
+
+    public String toString() {
+        return _wrappedFacesEvent.toString();
+    }
+
+    public boolean isAppropriateListener(FacesListener faceslistener) {
+        return _wrappedFacesEvent.isAppropriateListener(faceslistener);
+    }
+
+    public void processListener(FacesListener faceslistener) {
+        _wrappedFacesEvent.processListener(faceslistener);
+    }
+
+    public FacesEvent getWrappedFacesEvent() {
+        return _wrappedFacesEvent;
+    }
+}
\ No newline at end of file

Propchange: 
myfaces/trunk/src/components/org/apache/myfaces/custom/aliasbean/FacesEventWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: myfaces/trunk/tlds/myfaces_ext.tld
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/tlds/myfaces_ext.tld?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
--- myfaces/trunk/tlds/myfaces_ext.tld (original)
+++ myfaces/trunk/tlds/myfaces_ext.tld Sat May  7 14:20:15 2005
@@ -1941,9 +1941,12 @@
         <tag-class>org.apache.myfaces.custom.aliasbean.AliasBeanTag</tag-class>
         <body-content>JSP</body-content>
         <description>
-            A tage that defines a new bean (alias) with a given value.
-            This allows you to design a subform with a fictive bean and to 
include it in all the pages where you use it.
-                       You just need to make an alias to the real bean named 
after the fictive bean before including the subform.
+            A tag that defines a new bean (alias) with a given value.
+            This allows you to design a subform with a generic (fictive) beans 
and to include it in all the pages where you use it.
+                       You just need to make an alias to the real bean named 
after the generic bean before including the subform.
+                       
+                       When used within an aliasBeansScope tag, this tag adds 
the alias to the aliasBeansScope.
+                       This makes configuration with multiple aliasBeans 
easier to write.
         </description>
         <attribute>
             <name>id</name>
@@ -1952,20 +1955,37 @@
         </attribute>
         <attribute>
             <name>alias</name>
-            <required>true</required>
+            <required>false</required>
             <rtexprvalue>false</rtexprvalue>
             <description>
-                The name of the bean that will be set to the given value.
+                The bean that will be set to the given value.
+                Example : #{holder}
             </description>
         </attribute>
         <attribute>
             <name>value</name>
-            <required>true</required>
+            <required>false</required>
             <rtexprvalue>false</rtexprvalue>
             <description>
                 The value that the alias can be set to.
                                This can be a string (like "toto") or a 
reference to an existing bean (like "#{myBean.member1}").
             </description>
+        </attribute>
+    </tag>
+    <tag>
+        <name>aliasBeansScope</name>
+        
<tag-class>org.apache.myfaces.custom.aliasbean.AliasBeansScopeTag</tag-class>
+        <body-content>JSP</body-content>
+        <description>
+            This is like an aliasBean tag, but instead of the alias/value 
attributes, you configure the aliases
+            by adding aliasBean tags in the body.
+            
+            The aliasBeans should be declared right after this tag.
+        </description>
+        <attribute>
+            <name>id</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
         </attribute>
     </tag>
 

Modified: myfaces/trunk/webapps/simple/WEB-INF/examples-config.xml
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/webapps/simple/WEB-INF/examples-config.xml?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
--- myfaces/trunk/webapps/simple/WEB-INF/examples-config.xml (original)
+++ myfaces/trunk/webapps/simple/WEB-INF/examples-config.xml Sat May  7 
14:20:15 2005
@@ -58,6 +58,18 @@
         
<managed-bean-class>org.apache.myfaces.examples.aliasexample.AliasHolder</managed-bean-class>
         <managed-bean-scope>request</managed-bean-scope>
     </managed-bean>
+    
+    <managed-bean>
+        <managed-bean-name>aliasTest3</managed-bean-name>
+        
<managed-bean-class>org.apache.myfaces.examples.aliasexample.AliasHolder</managed-bean-class>
+        <managed-bean-scope>request</managed-bean-scope>
+    </managed-bean>
+    
+    <managed-bean>
+        <managed-bean-name>aliasTest4</managed-bean-name>
+        
<managed-bean-class>org.apache.myfaces.examples.aliasexample.AliasHolder</managed-bean-class>
+        <managed-bean-scope>request</managed-bean-scope>
+    </managed-bean>
 
     <!-- Managed Beans for selectbox.jsp -->
 

Modified: myfaces/trunk/webapps/simple/aliasBean.jsp
URL: 
http://svn.apache.org/viewcvs/myfaces/trunk/webapps/simple/aliasBean.jsp?rev=169110&r1=169109&r2=169110&view=diff
==============================================================================
Binary files - no diff available.


Reply via email to