[richfaces-svn-commits] JBoss Rich Faces SVN: r5061 - trunk/ui/columns/src/main/java/org/richfaces/taglib.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Dec 28 07:12:06 EST 2007


Author: andrei_exadel
Date: 2007-12-28 07:12:06 -0500 (Fri, 28 Dec 2007)
New Revision: 5061

Added:
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ActionSourceRule.java
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentRule.java
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ValueHolderRule.java
Modified:
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
   trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTagHandler.java
Log:
RF-1795 

Added: trunk/ui/columns/src/main/java/org/richfaces/taglib/ActionSourceRule.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ActionSourceRule.java	                        (rev 0)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ActionSourceRule.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -0,0 +1,138 @@
+/**
+ * Licensed under the Common Development and Distribution License,
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.sun.com/cddl/
+ *   
+ * 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.richfaces.taglib;
+
+import javax.faces.component.ActionSource;
+import javax.faces.component.ActionSource2;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.MethodExpressionActionListener;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyMethodBinding;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.util.FacesAPI;
+
+/**
+ * 
+ * @author Jacob Hookom
+ * @version $Id: ActionSourceRule.java,v 1.2 2005/08/24 04:38:50 jhook Exp $
+ */
+final class ActionSourceRule extends MetaRule {
+
+    public final static Class[] ACTION_SIG = new Class[0];
+
+    public final static Class[] ACTION_LISTENER_SIG = new Class[] { ActionEvent.class };
+
+    final static class ActionMapper extends Metadata {
+
+        private final TagAttribute attr;
+
+        public ActionMapper(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ActionSource) instance).setAction(new LegacyMethodBinding(
+                    this.attr.getMethodExpression(ctx, String.class,
+                            ActionSourceRule.ACTION_SIG)));
+        }
+    }
+
+    final static class ActionMapper2 extends Metadata {
+
+        private final TagAttribute attr;
+
+        public ActionMapper2(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ActionSource2) instance).setActionExpression(this.attr
+                    .getMethodExpression(ctx, String.class,
+                            ActionSourceRule.ACTION_SIG));
+        }
+
+    }
+
+    final static class ActionListenerMapper extends Metadata {
+
+        private final TagAttribute attr;
+
+        public ActionListenerMapper(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ActionSource) instance)
+                    .setActionListener(new LegacyMethodBinding(this.attr
+                            .getMethodExpression(ctx, null,
+                                    ActionSourceRule.ACTION_LISTENER_SIG)));
+        }
+
+    }
+
+    final static class ActionListenerMapper2 extends Metadata {
+
+        private final TagAttribute attr;
+
+        public ActionListenerMapper2(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ActionSource2) instance)
+                    .addActionListener(new MethodExpressionActionListener(
+                            this.attr.getMethodExpression(ctx, null,
+                                    ActionSourceRule.ACTION_LISTENER_SIG)));
+
+        }
+
+    }
+
+    public final static ActionSourceRule Instance = new ActionSourceRule();
+
+    public ActionSourceRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(ActionSource.class)) {
+
+            boolean elSupport = FacesAPI.getComponentVersion(meta
+                    .getTargetClass()) >= 12;
+
+            if ("action".equals(name)) {
+                if (elSupport) {
+                    return new ActionMapper2(attribute);
+                } else {
+                    return new ActionMapper(attribute);
+                }
+            }
+
+            if ("actionListener".equals(name)) {
+                if (elSupport) {
+                    return new ActionListenerMapper2(attribute);
+                } else {
+                    return new ActionListenerMapper(attribute);
+                }
+            }
+        }
+        return null;
+    }
+}

Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java	2007-12-28 10:04:34 UTC (rev 5060)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -502,6 +502,7 @@
 	}
 	UIComponent component = createColumn();
 	pushUIComponentClassicTagBase(this);
+	
 	dataTable.getChildren().add(component);
 
 	next();
@@ -564,7 +565,7 @@
 	prepare();
 
 	if (created) {
-	    //dataTable.getChildren().clear();
+	    dataTable.getChildren().clear();
 	    created = false;
 	}
 

Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTagHandler.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTagHandler.java	2007-12-28 10:04:34 UTC (rev 5060)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTagHandler.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -26,8 +26,8 @@
 import com.sun.facelets.FaceletContext;
 import com.sun.facelets.tag.TagAttribute;
 import com.sun.facelets.tag.jsf.ComponentConfig;
-import com.sun.facelets.tag.jsf.ComponentHandler;
 
+
 /**
  * TODO Class description goes here.
  * 
@@ -78,12 +78,6 @@
     /** Current column counter */
     private Integer _index = 0;
 
-    /** Prepared flag */
-    private boolean prepared = false;
-
-    /** Variables counter */
-    private int vCounter;
-
     /** Expression for var item */
     private IteratedExpression iteratedExpression;
 
@@ -141,12 +135,6 @@
 	}
 
 	correctFirst(ctx);
-
-	if (hasNext()) {
-	    exposeVariables(ctx, 0);
-	    next(ctx);
-	}
-
     }
 
     /**
@@ -227,7 +215,7 @@
 	if (begin != null) {
 	    try {
 		_begin = Integer.parseInt((String) begin.getObject(ctx));
-		_begin--; // - 1
+		_begin--;
 		if (_begin < 0) {
 		    _begin = 0; // If end is negative set up zero
 		}
@@ -287,49 +275,38 @@
 
 	}
     }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see com.sun.facelets.tag.jsf.ComponentHandler#applyNextHandler(com.sun.facelets.FaceletContext,
-     *      javax.faces.component.UIComponent)
+    
+    /* (non-Javadoc)
+     * @see org.richfaces.taglib.ComponentHandler#apply(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent)
      */
     @Override
-    protected void applyNextHandler(FaceletContext ctx, UIComponent c)
+    public void apply(FaceletContext ctx, UIComponent parent)
 	    throws IOException, FacesException, ELException {
-	// TODO Auto-generated method stub
-	super.applyNextHandler(ctx, c);
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see com.sun.facelets.tag.jsf.ComponentHandler#onComponentCreated(com.sun.facelets.FaceletContext,
-     *      javax.faces.component.UIComponent,
-     *      javax.faces.component.UIComponent)
-     */
-    @Override
-    protected void onComponentCreated(FaceletContext ctx, UIComponent c,
-	    UIComponent parent) {
-	// prepare if did not
-	if (!prepared) {
-	    prepare(ctx);
-	    prepared = true;
-	}
-
-	// for each
+	
+	prepare(ctx);  // prepare data 
+		
 	try {
-	    if (hasNext()) {
-		next(ctx);
+	    while (hasNext()) {  // for each
+		exposeVariables(ctx, _index);
 		super.apply(ctx, parent);
-	    } else {
-		vCounter = 1;
+		next(ctx);
 	    }
 	} catch (Exception e) {
 	    // TODO: handle exception
+	} finally {
+	    release();
+	    unExposeVariables(ctx);
 	}
+	
     }
 
+    protected void applyNextHandler(FaceletContext ctx, UIComponent c)
+	    throws IOException, FacesException, ELException {
+	// TODO Auto-generated method stub
+	super.applyNextHandler(ctx, c);
+    }
+
+  
     /**
      * Sets page request variables
      * 
@@ -344,8 +321,7 @@
 		if (value != null) {
 		    ValueExpression srcVE = value.getValueExpression(ctx,
 			    Object.class);
-		    ValueExpression ve = getVarExpression(ctx, srcVE, k
-			    + _begin);
+		    ValueExpression ve = getVarExpression(ctx, srcVE, k);
 		    vm.setVariable(_itemId, ve);
 		}
 	    }
@@ -408,48 +384,10 @@
     }
 
     /**
-     * Returns true if this is the first loop of columns tag
-     * 
-     * @return
-     */
-    private boolean atFirst() {
-	return (_index == 0);
-    }
-
-    /**
      * Release iteration variables
      */
     private void release() {
 	this.items = null;
 	this._index = 0;
-	this.prepared = false;
     }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see com.sun.facelets.tag.jsf.ComponentHandler#onComponentPopulated(com.sun.facelets.FaceletContext,
-     *      javax.faces.component.UIComponent,
-     *      javax.faces.component.UIComponent)
-     */
-    @Override
-    protected void onComponentPopulated(FaceletContext ctx, UIComponent c,
-	    UIComponent parent) {
-
-	// remove created component if columns count is zero
-	if (atFirst()) {
-	    c.setRendered(false);
-	}
-
-	if ((vCounter == (_index - _begin)) || atFirst()) {
-	    release();
-	    unExposeVariables(ctx);
-	    return;
-	}
-
-	exposeVariables(ctx, vCounter);
-	vCounter++;
-
-    }
-
 }

Added: trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java	                        (rev 0)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -0,0 +1,298 @@
+/**
+ * Licensed under the Common Development and Distribution License,
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.sun.com/cddl/
+ *   
+ * 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.richfaces.taglib;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.component.ActionSource;
+import javax.faces.component.ActionSource2;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.MethodExpressionActionListener;
+import javax.faces.event.MethodExpressionValueChangeListener;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.validator.MethodExpressionValidator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.ELAdaptor;
+import com.sun.facelets.el.LegacyMethodBinding;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaTagHandler;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.TagException;
+import com.sun.facelets.tag.TagHandler;
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ComponentConfig;
+import com.sun.facelets.tag.jsf.ComponentSupport;
+import com.sun.facelets.tag.jsf.EditableValueHolderRule;
+import com.sun.facelets.util.FacesAPI;
+
+/**
+ * Implementation of the tag logic used in the JSF specification. This is your
+ * golden hammer for wiring UIComponents to Facelets.
+ * 
+ * @author Jacob Hookom
+ * @version $Id: ComponentHandler.java,v 1.12 2006/01/11 05:40:56 jhook Exp $
+ */
+public class ComponentHandler extends MetaTagHandler {
+
+    private final static Logger log = Logger
+            .getLogger("facelets.tag.component");
+    
+    private final TagAttribute binding;
+
+    private final String componentType;
+
+    private final TagAttribute id;
+
+    private final String rendererType;
+
+    public ComponentHandler(ComponentConfig config) {
+        super(config);
+        this.componentType = config.getComponentType();
+        this.rendererType = config.getRendererType();
+        this.id = this.getAttribute("id");
+        this.binding = this.getAttribute("binding");
+    }
+
+    /**
+     * Method handles UIComponent tree creation in accordance with the JSF 1.2
+     * spec.
+     * <ol>
+     * <li>First determines this UIComponent's id by calling
+     * {@link #getId(FaceletContext) getId(FaceletContext)}.</li>
+     * <li>Search the parent for an existing UIComponent of the id we just
+     * grabbed</li>
+     * <li>If found, {@link #markForDeletion(UIComponent) mark} its children
+     * for deletion.</li>
+     * <li>If <i>not</i> found, call
+     * {@link #createComponent(FaceletContext) createComponent}.
+     * <ol>
+     * <li>Only here do we apply
+     * {@link ObjectHandler#setAttributes(FaceletContext, Object) attributes}</li>
+     * <li>Set the UIComponent's id</li>
+     * <li>Set the RendererType of this instance</li>
+     * </ol>
+     * </li>
+     * <li>Now apply the nextHandler, passing the UIComponent we've
+     * created/found.</li>
+     * <li>Now add the UIComponent to the passed parent</li>
+     * <li>Lastly, if the UIComponent already existed (found), then
+     * {@link #finalizeForDeletion(UIComponent) finalize} for deletion.</li>
+     * </ol>
+     * 
+     * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
+     *      javax.faces.component.UIComponent)
+     * 
+     * @throws TagException
+     *             if the UIComponent parent is null
+     */
+    public void apply(FaceletContext ctx, UIComponent parent)
+            throws IOException, FacesException, ELException {
+        // make sure our parent is not null
+        if (parent == null) {
+            throw new TagException(this.tag, "Parent UIComponent was null");
+        }
+
+        // our id
+        String id = ctx.generateUniqueId(this.tagId);
+
+        // grab our component
+        UIComponent c = ComponentSupport.findChildByTagId(parent, id);
+        boolean componentFound = false;
+        if (c != null) {
+            componentFound = true;
+            // mark all children for cleaning
+            if (log.isLoggable(Level.FINE)) {
+                log.fine(this.tag
+                        + " Component["+id+"] Found, marking children for cleanup");
+            }
+            ComponentSupport.markForDeletion(c);
+        } else {
+            c = this.createComponent(ctx);
+            if (log.isLoggable(Level.FINE)) {
+                log.fine(this.tag + " Component["+id+"] Created: "
+                        + c.getClass().getName());
+            }
+            this.setAttributes(ctx, c);
+            
+            // mark it owned by a facelet instance
+            c.getAttributes().put(ComponentSupport.MARK_CREATED, id);
+            
+            // assign our unique id
+            if (this.id != null) {
+                c.setId(ctx.generateUniqueId(this.id.getValue(ctx)));
+            } else {
+                UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
+                if (root != null) {
+                    c.setId(root.createUniqueId());
+                }
+            }
+            
+            if (this.rendererType != null) {
+                c.setRendererType(this.rendererType);
+            }
+            
+            // hook method
+            this.onComponentCreated(ctx, c, parent);
+        }
+
+        // first allow c to get populated
+        this.nextHandler.apply(ctx, c);
+
+        // finish cleaning up orphaned children
+        if (componentFound) {
+            ComponentSupport.finalizeForDeletion(c);
+            parent.getChildren().remove(c);
+        }
+        
+        // add to the tree afterwards
+        // this allows children to determine if it's
+        // been part of the tree or not yet
+        parent.getChildren().add(c);
+    }
+    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.sun.facelets.tag.jsf.ComponentHandler#applyNextHandler(com.sun.facelets.FaceletContext,
+     *      javax.faces.component.UIComponent)
+     */
+    
+    protected void applyNextHandler(FaceletContext ctx, UIComponent c)
+	    throws IOException, FacesException, ELException {
+	
+    }
+
+    /**
+     * If the binding attribute was specified, use that in conjuction with our
+     * componentType String variable to call createComponent on the Application,
+     * otherwise just pass the componentType String.
+     * <p />
+     * If the binding was used, then set the ValueExpression "binding" on the
+     * created UIComponent.
+     * 
+     * @see Application#createComponent(javax.faces.el.ValueBinding,
+     *      javax.faces.context.FacesContext, java.lang.String)
+     * @see Application#createComponent(java.lang.String)
+     * @param ctx
+     *            FaceletContext to use in creating a component
+     * @return
+     */
+    protected UIComponent createComponent(FaceletContext ctx) {
+        UIComponent c = null;
+        FacesContext faces = ctx.getFacesContext();
+        Application app = faces.getApplication();
+        if (this.binding != null) {
+            ValueExpression ve = this.binding.getValueExpression(ctx,
+                    Object.class);
+            if (FacesAPI.getVersion() >= 12) {
+                c = app.createComponent(ve, faces, this.componentType);
+                if (c != null) {
+                    // Make sure the component supports 1.2
+                    if (FacesAPI.getComponentVersion(c) >= 12) {
+                        c.setValueExpression("binding", ve);
+                    } else {
+                        ValueBinding vb = new LegacyValueBinding(ve);
+                        c.setValueBinding("binding", vb);
+                    }
+
+                }
+            } else {
+                ValueBinding vb = new LegacyValueBinding(ve);
+                c = app.createComponent(vb, faces, this.componentType);
+                if (c != null) {
+                    c.setValueBinding("binding", vb);
+                }
+            }
+        } else {
+            c = app.createComponent(this.componentType);
+        }
+        return c;
+    }
+
+    /**
+     * If the id TagAttribute was specified, get it's value, otherwise generate
+     * a unique id from our tagId.
+     * 
+     * @see TagAttribute#getValue(FaceletContext)
+     * @param ctx
+     *            FaceletContext to use
+     * @return what should be a unique Id
+     */
+    protected String getId(FaceletContext ctx) {
+        if (this.id != null) {
+            return this.id.getValue(ctx);
+        }
+        return ctx.generateUniqueId(this.tagId);
+    }
+
+    protected MetaRuleset createMetaRuleset(Class type) {
+        MetaRuleset m = super.createMetaRuleset(type);
+        
+        // ignore standard component attributes
+        m.ignore("binding").ignore("id");
+        
+        // add auto wiring for attributes
+        m.addRule(ComponentRule.Instance);
+        
+        // if it's an ActionSource
+        if (ActionSource.class.isAssignableFrom(type)) {
+            m.addRule(ActionSourceRule.Instance);
+        }
+        
+        // if it's a ValueHolder
+        if (ValueHolder.class.isAssignableFrom(type)) {
+            m.addRule(ValueHolderRule.Instance);
+            
+            // if it's an EditableValueHolder
+            if (EditableValueHolder.class.isAssignableFrom(type)) {
+                m.ignore("submittedValue");
+                m.ignore("valid");
+                m.addRule(EditableValueHolderRule.Instance);
+            }
+        }
+        
+        return m;
+    }
+    
+    /**
+     * A hook method for allowing developers to do additional processing once Facelets
+     * creates the component.  The 'setAttributes' method is still perferred, but this
+     * method will provide the parent UIComponent before it's been added to the tree and
+     * before any children have been added to the newly created UIComponent.
+     * 
+     * @param ctx
+     * @param c
+     * @param parent
+     */
+    protected void onComponentCreated(FaceletContext ctx, UIComponent c, UIComponent parent) {
+        // do nothing
+    }
+}

Added: trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentRule.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentRule.java	                        (rev 0)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentRule.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -0,0 +1,139 @@
+/**
+ * Licensed under the Common Development and Distribution License,
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.sun.com/cddl/
+ *   
+ * 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.richfaces.taglib;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.util.FacesAPI;
+
+/**
+ * 
+ * @author Jacob Hookom
+ * @version $Id: ComponentRule.java,v 1.2 2005/08/24 04:38:50 jhook Exp $
+ */
+final class ComponentRule extends MetaRule {
+
+    final class LiteralAttributeMetadata extends Metadata {
+
+        private final String name;
+        private final String value;
+        
+        public LiteralAttributeMetadata(String name, String value) {
+            this.value = value;
+            this.name = name;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((UIComponent) instance).getAttributes().put(this.name, this.value);
+        }
+    }
+    
+    final static class ValueExpressionMetadata extends Metadata {
+
+        private final String name;
+
+        private final TagAttribute attr;
+
+        private final Class type;
+
+        public ValueExpressionMetadata(String name, Class type,
+                TagAttribute attr) {
+            this.name = name;
+            this.attr = attr;
+            this.type = type;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((UIComponent) instance).setValueExpression(this.name, this.attr
+                    .getValueExpression(ctx, this.type));
+        }
+
+    }
+
+    final static class ValueBindingMetadata extends Metadata {
+
+        private final String name;
+
+        private final TagAttribute attr;
+
+        private final Class type;
+
+        public ValueBindingMetadata(String name, Class type, TagAttribute attr) {
+            this.name = name;
+            this.attr = attr;
+            this.type = type;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((UIComponent) instance).setValueBinding(this.name,
+                    new LegacyValueBinding(this.attr.getValueExpression(ctx,
+                            this.type)));
+        }
+
+    }
+
+    private final static Logger log = Logger
+            .getLogger("facelets.tag.component");
+
+    public final static ComponentRule Instance = new ComponentRule();
+
+    public ComponentRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(UIComponent.class)) {
+
+            // if component and dynamic, then must set expression
+            if (!attribute.isLiteral()) {
+                Class type = meta.getPropertyType(name);
+                if (type == null) {
+                    type = Object.class;
+                }
+                if (FacesAPI.getComponentVersion(meta.getTargetClass()) >= 12) {
+                    return new ValueExpressionMetadata(name, type, attribute);
+                } else {
+                    return new ValueBindingMetadata(name, type, attribute);
+                }
+            } else if (meta.getWriteMethod(name) == null) {
+
+                // this was an attribute literal, but not property
+                warnAttr(attribute, meta.getTargetClass(), name);
+
+                return new LiteralAttributeMetadata(name, attribute.getValue());
+            }
+        }
+        return null;
+    }
+
+    private static void warnAttr(TagAttribute attr, Class type, String n) {
+        if (log.isLoggable(Level.WARNING)) {
+            log.warning(attr + " Property '" + n + "' is not on type: "
+                    + type.getName());
+        }
+    }
+
+}

Added: trunk/ui/columns/src/main/java/org/richfaces/taglib/ValueHolderRule.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ValueHolderRule.java	                        (rev 0)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ValueHolderRule.java	2007-12-28 12:12:06 UTC (rev 5061)
@@ -0,0 +1,135 @@
+/**
+ * Licensed under the Common Development and Distribution License,
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.sun.com/cddl/
+ *   
+ * 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.richfaces.taglib;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.convert.Converter;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.util.FacesAPI;
+
+/**
+ * 
+ * @author Jacob Hookom
+ * @version $Id: ValueHolderRule.java,v 1.2 2005/08/24 04:38:51 jhook Exp $
+ */
+final class ValueHolderRule extends MetaRule {
+
+    final static class LiteralConverterMetadata extends Metadata {
+
+        private final String converterId;
+
+        public LiteralConverterMetadata(String converterId) {
+            this.converterId = converterId;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ValueHolder) instance).setConverter(ctx.getFacesContext()
+                    .getApplication().createConverter(this.converterId));
+        }
+    }
+
+    final static class DynamicConverterMetadata extends Metadata {
+
+        private final TagAttribute attr;
+
+        public DynamicConverterMetadata(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ValueHolder) instance).setConverter((Converter) this.attr
+                    .getObject(ctx, Converter.class));
+        }
+    }
+
+    final static class LiteralValueMetadata extends Metadata {
+
+        private final String value;
+
+        public LiteralValueMetadata(String value) {
+            this.value = value;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((ValueHolder) instance).setValue(this.value);
+        }
+    }
+
+    final static class DynamicValueExpressionMetadata extends Metadata {
+
+        private final TagAttribute attr;
+
+        public DynamicValueExpressionMetadata(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((UIComponent) instance).setValueExpression("value", attr
+                    .getValueExpression(ctx, Object.class));
+        }
+    }
+
+    final static class DynamicValueBindingMetadata extends Metadata {
+
+        private final TagAttribute attr;
+
+        public DynamicValueBindingMetadata(TagAttribute attr) {
+            this.attr = attr;
+        }
+
+        public void applyMetadata(FaceletContext ctx, Object instance) {
+            ((UIComponent) instance).setValueBinding("value",
+                    new LegacyValueBinding(attr.getValueExpression(ctx,
+                            Object.class)));
+        }
+    }
+
+    public final static ValueHolderRule Instance = new ValueHolderRule();
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(ValueHolder.class)) {
+
+            if ("converter".equals(name)) {
+                if (attribute.isLiteral()) {
+                    return new LiteralConverterMetadata(attribute.getValue());
+                } else {
+                    return new DynamicConverterMetadata(attribute);
+                }
+            }
+
+            if ("value".equals(name)) {
+                if (attribute.isLiteral()) {
+                    return new LiteralValueMetadata(attribute.getValue());
+                } else {
+                    if (FacesAPI.getComponentVersion(meta.getTargetClass()) >= 12) {
+                        return new DynamicValueExpressionMetadata(attribute);
+                    } else {
+                        return new DynamicValueBindingMetadata(attribute);
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+}




More information about the richfaces-svn-commits mailing list