You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sl...@apache.org on 2009/04/04 20:45:04 UTC
svn commit: r761982 [7/10] - in /myfaces/core/branches/2_0_0/impl/src:
main/java/com/ main/java/org/apache/myfaces/application/
main/java/org/apache/myfaces/config/
main/java/org/apache/myfaces/config/impl/digester/
main/java/org/apache/myfaces/config/...
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/UserTagHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,153 @@
+/*
+ * 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.view.facelets.tag;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.el.ELException;
+import javax.el.VariableMapper;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.TagHandler;
+
+import org.apache.myfaces.view.facelets.TemplateClient;
+import org.apache.myfaces.view.facelets.el.VariableMapperWrapper;
+import org.apache.myfaces.view.facelets.tag.ui.DefineHandler;
+
+/**
+ * A Tag that is specified in a FaceletFile. Takes all attributes specified and sets them on the FaceletContext before
+ * including the targeted Facelet file.
+ *
+ * @author Jacob Hookom
+ * @version $Id: UserTagHandler.java,v 1.12 2008/07/13 19:01:35 rlubke Exp $
+ */
+final class UserTagHandler extends TagHandler implements TemplateClient
+{
+
+ protected final TagAttribute[] _vars;
+
+ protected final URL _location;
+
+ protected final Map<String, DefineHandler> _handlers;
+
+ /**
+ * @param config
+ */
+ public UserTagHandler(TagConfig config, URL location)
+ {
+ super(config);
+ this._vars = this.tag.getAttributes().getAll();
+ this._location = location;
+
+ Collection<DefineHandler> defines = TagHandlerUtils.findNextByType(nextHandler, DefineHandler.class);
+ if (defines.isEmpty())
+ {
+ _handlers = null;
+ }
+ else
+ {
+ _handlers = new HashMap<String, DefineHandler>();
+ for (DefineHandler handler : defines)
+ {
+ _handlers.put(handler.getName(), handler);
+ }
+ }
+ }
+
+ /**
+ * Iterate over all TagAttributes and set them on the FaceletContext's VariableMapper, then include the target
+ * Facelet. Finally, replace the old VariableMapper.
+ *
+ * @see TagAttribute#getValueExpression(FaceletContext, Class)
+ * @see VariableMapper
+ * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
+ ELException
+ {
+ VariableMapper orig = ctx.getVariableMapper();
+
+ // setup a variable map
+ if (this._vars.length > 0)
+ {
+ VariableMapper varMapper = new VariableMapperWrapper(orig);
+ for (int i = 0; i < this._vars.length; i++)
+ {
+ varMapper.setVariable(this._vars[i].getLocalName(), this._vars[i].getValueExpression(ctx, Object.class));
+ }
+ ctx.setVariableMapper(varMapper);
+ }
+
+ // eval include
+ try
+ {
+ //ctx.pushClient(this);
+ ctx.includeFacelet(parent, this._location);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new TagException(this.tag, e.getMessage());
+ }
+ finally
+ {
+
+ // make sure we undo our changes
+ //ctx.popClient(this);
+ ctx.setVariableMapper(orig);
+ }
+ }
+
+ public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
+ FaceletException, ELException
+ {
+ if (name != null)
+ {
+ if (this._handlers == null)
+ {
+ return false;
+ }
+ DefineHandler handler = (DefineHandler) this._handlers.get(name);
+ if (handler != null)
+ {
+ handler.applyDefinition(ctx, parent);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ this.nextHandler.apply(ctx, parent);
+ return true;
+ }
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ActionSourceRule.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ActionSourceRule.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ActionSourceRule.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ActionSourceRule.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,99 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import javax.el.MethodExpression;
+import javax.faces.component.ActionSource;
+import javax.faces.component.ActionSource2;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.MethodExpressionActionListener;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ * @author Jacob Hookom
+ * @version $Id: ActionSourceRule.java,v 1.5 2008/07/13 19:01:46 rlubke 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 ActionMapper2 extends Metadata
+ {
+ private final TagAttribute _attr;
+
+ public ActionMapper2(TagAttribute attr)
+ {
+ this._attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ MethodExpression expr = _attr.getMethodExpression(ctx, String.class, ActionSourceRule.ACTION_SIG);
+ ((ActionSource2) instance).setActionExpression(expr);
+ }
+ }
+
+ final static class ActionListenerMapper2 extends Metadata
+ {
+ private final TagAttribute _attr;
+
+ public ActionListenerMapper2(TagAttribute attr)
+ {
+ _attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ MethodExpression expr = _attr.getMethodExpression(ctx, null, ActionSourceRule.ACTION_LISTENER_SIG);
+ ((ActionSource2) instance).addActionListener(new MethodExpressionActionListener(expr));
+ }
+ }
+
+ public final static ActionSourceRule Instance = new ActionSourceRule();
+
+ public ActionSourceRule()
+ {
+ super();
+ }
+
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
+ {
+ if (meta.isTargetInstanceOf(ActionSource.class))
+ {
+ if ("action".equals(name))
+ {
+ return new ActionMapper2(attribute);
+ }
+
+ if ("actionListener".equals(name))
+ {
+ return new ActionListenerMapper2(attribute);
+ }
+ }
+
+ return null;
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,311 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.application.Application;
+import javax.faces.component.ActionSource;
+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.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.MetaTagHandler;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagException;
+
+/**
+ * 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.19 2008/07/13 19:01:47 rlubke 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 javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ *
+ * @throws TagException
+ * if the UIComponent parent is null
+ */
+ public final 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");
+ }
+
+ // possible facet scoped
+ String facetName = this.getFacetName(ctx, parent);
+
+ // 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(this.id.getValue(ctx));
+ }
+ else
+ {
+ UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
+ if (root != null)
+ {
+ String uid = root.createUniqueId();
+ c.setId(uid);
+ }
+ }
+
+ if (this.rendererType != null)
+ {
+ c.setRendererType(this.rendererType);
+ }
+
+ // hook method
+ this.onComponentCreated(ctx, c, parent);
+ }
+
+ // first allow c to get populated
+ this.applyNextHandler(ctx, c);
+
+ // finish cleaning up orphaned children
+ if (componentFound)
+ {
+ ComponentSupport.finalizeForDeletion(c);
+
+ if (facetName == null)
+ {
+ parent.getChildren().remove(c);
+ }
+ }
+
+ this.onComponentPopulated(ctx, c, parent);
+
+ // add to the tree afterwards
+ // this allows children to determine if it's
+ // been part of the tree or not yet
+ if (facetName == null)
+ {
+ parent.getChildren().add(c);
+ }
+ else
+ {
+ parent.getFacets().put(facetName, c);
+ }
+ }
+
+ /**
+ * Return the Facet name we are scoped in, otherwise null
+ *
+ * @param ctx
+ * @return
+ */
+ protected final String getFacetName(FaceletContext ctx, UIComponent parent)
+ {
+ // TODO: REFACTOR - "facelets.FACET_NAME" should be a constant somewhere, used to be in FacetHandler
+ // from real Facelets
+ return (String) parent.getAttributes().get("facelets.FACET_NAME");
+ }
+
+ /**
+ * 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);
+
+ c = app.createComponent(ve, faces, this.componentType);
+ if (c != null)
+ {
+ c.setValueExpression("binding", ve);
+ }
+ }
+ 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);
+ }
+
+ @Override
+ 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;*/
+
+ // FIXME: Implement correctly
+ return null;
+ }
+
+ /**
+ * 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
+ }
+
+ protected void onComponentPopulated(FaceletContext ctx, UIComponent c, UIComponent parent)
+ {
+ // do nothing
+ }
+
+ protected void applyNextHandler(FaceletContext ctx, UIComponent c) throws IOException, FacesException, ELException
+ {
+ // first allow c to get populated
+ this.nextHandler.apply(ctx, c);
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRule.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRule.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRule.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentRule.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,121 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ * @author Jacob Hookom
+ * @version $Id: ComponentRule.java,v 1.4 2008/07/13 19:01:47 rlubke 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)
+ {
+ _name = name;
+ _value = value;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((UIComponent) instance).getAttributes().put(_name, _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)
+ {
+ _name = name;
+ _attr = attr;
+ _type = type;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((UIComponent) instance).setValueExpression(_name, _attr.getValueExpression(ctx, _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;
+ }
+
+ return new ValueExpressionMetadata(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.FINER))
+ {
+ log.finer(attr + " Property '" + n + "' is not on type: " + type.getName());
+ }
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,299 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributeException;
+
+/**
+ *
+ * @author Jacob Hookom
+ * @version $Id: ComponentSupport.java,v 1.8 2008/07/13 19:01:46 rlubke Exp $
+ */
+public final class ComponentSupport
+{
+
+ private final static String MARK_DELETED = "org.apache.myfaces.view.facelets.MARK_DELETED";
+ public final static String MARK_CREATED = "org.apache.myfaces.view.facelets.MARK_ID";
+
+ /**
+ * Used in conjunction with markForDeletion where any UIComponent marked will be removed.
+ *
+ * @param component
+ * UIComponent to finalize
+ */
+ public static void finalizeForDeletion(UIComponent component)
+ {
+ // remove any existing marks of deletion
+ component.getAttributes().remove(MARK_DELETED);
+
+ // finally remove any children marked as deleted
+ if (component.getChildCount() > 0)
+ {
+ for (Iterator<UIComponent> iter = component.getChildren().iterator(); iter.hasNext();)
+ {
+ UIComponent child = iter.next();
+ if (child.getAttributes().containsKey(MARK_DELETED))
+ {
+ iter.remove();
+ }
+ }
+ }
+
+ // remove any facets marked as deleted
+ Map<String, UIComponent> facets = component.getFacets();
+ if (!facets.isEmpty())
+ {
+ Collection<UIComponent> col = facets.values();
+ for (Iterator<UIComponent> itr = col.iterator(); itr.hasNext();)
+ {
+ UIComponent fc = itr.next();
+ if (fc.getAttributes().containsKey(MARK_DELETED))
+ {
+ itr.remove();
+ }
+ }
+ }
+ }
+
+ /**
+ * A lighter-weight version of UIComponent's findChild.
+ *
+ * @param parent
+ * parent to start searching from
+ * @param id
+ * to match to
+ * @return UIComponent found or null
+ */
+ public static UIComponent findChild(UIComponent parent, String id)
+ {
+ if (parent.getChildCount() > 0)
+ {
+ for (UIComponent child : parent.getChildren())
+ {
+ if (id.equals(child.getId()))
+ {
+ return child;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * By TagId, find Child
+ *
+ * @param parent
+ * @param id
+ * @return
+ */
+ public static UIComponent findChildByTagId(UIComponent parent, String id)
+ {
+ Iterator<UIComponent> itr = parent.getFacetsAndChildren();
+ while (itr.hasNext())
+ {
+ UIComponent child = itr.next();
+ if (id.equals(child.getAttributes().get(MARK_CREATED)))
+ {
+ return child;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * According to JSF 1.2 tag specs, this helper method will use the TagAttribute passed in determining the Locale
+ * intended.
+ *
+ * @param ctx
+ * FaceletContext to evaluate from
+ * @param attr
+ * TagAttribute representing a Locale
+ * @return Locale found
+ * @throws TagAttributeException
+ * if the Locale cannot be determined
+ */
+ public static Locale getLocale(FaceletContext ctx, TagAttribute attr) throws TagAttributeException
+ {
+ Object obj = attr.getObject(ctx);
+ if (obj instanceof Locale)
+ {
+ return (Locale) obj;
+ }
+ if (obj instanceof String)
+ {
+ String s = (String) obj;
+ if (s.length() == 2)
+ {
+ return new Locale(s);
+ }
+
+ if (s.length() == 5)
+ {
+ return new Locale(s.substring(0, 2), s.substring(3, 5).toUpperCase());
+ }
+
+ if (s.length() >= 7)
+ {
+ return new Locale(s.substring(0, 2), s.substring(3, 5).toUpperCase(), s.substring(6, s.length()));
+ }
+
+ throw new TagAttributeException(attr, "Invalid Locale Specified: " + s);
+ }
+ else
+ {
+ throw new TagAttributeException(attr, "Attribute did not evaluate to a String or Locale: " + obj);
+ }
+ }
+
+ /**
+ * Tries to walk up the parent to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for
+ * the view root.
+ *
+ * @param ctx
+ * FaceletContext
+ * @param parent
+ * UIComponent to search from
+ * @return UIViewRoot instance for this evaluation
+ */
+ public static UIViewRoot getViewRoot(FaceletContext ctx, UIComponent parent)
+ {
+ UIComponent c = parent;
+ do
+ {
+ if (c instanceof UIViewRoot)
+ {
+ return (UIViewRoot) c;
+ }
+ else
+ {
+ c = c.getParent();
+ }
+ } while (c != null);
+
+ return ctx.getFacesContext().getViewRoot();
+ }
+
+ /**
+ * Marks all direct children and Facets with an attribute for deletion.
+ *
+ * @see #finalizeForDeletion(UIComponent)
+ * @param component
+ * UIComponent to mark
+ */
+ public static void markForDeletion(UIComponent component)
+ {
+ // flag this component as deleted
+ component.getAttributes().put(MARK_DELETED, Boolean.TRUE);
+
+ Iterator<UIComponent> iter = component.getFacetsAndChildren();
+ while (iter.hasNext())
+ {
+ UIComponent child = iter.next();
+ if (child.getAttributes().containsKey(MARK_CREATED))
+ {
+ child.getAttributes().put(MARK_DELETED, Boolean.TRUE);
+ }
+ }
+ }
+
+ public static void encodeRecursive(FacesContext context, UIComponent toRender) throws IOException, FacesException
+ {
+ if (toRender.isRendered())
+ {
+ toRender.encodeBegin(context);
+
+ if (toRender.getRendersChildren())
+ {
+ toRender.encodeChildren(context);
+ }
+ else if (toRender.getChildCount() > 0)
+ {
+ for (UIComponent child : toRender.getChildren())
+ {
+ encodeRecursive(context, child);
+ }
+ }
+
+ toRender.encodeEnd(context);
+ }
+ }
+
+ public static void removeTransient(UIComponent component)
+ {
+ if (component.getChildCount() > 0)
+ {
+ for (Iterator<UIComponent> itr = component.getChildren().iterator(); itr.hasNext();)
+ {
+ UIComponent child = itr.next();
+ if (child.isTransient())
+ {
+ itr.remove();
+ }
+ else
+ {
+ removeTransient(child);
+ }
+ }
+ }
+
+ Map<String, UIComponent> facets = component.getFacets();
+ if (!facets.isEmpty())
+ {
+ for (Iterator<UIComponent> itr = facets.values().iterator(); itr.hasNext();)
+ {
+ UIComponent facet = itr.next();
+ if (facet.isTransient())
+ {
+ itr.remove();
+ }
+ else
+ {
+ removeTransient(facet);
+ }
+ }
+ }
+ }
+
+ /**
+ * Determine if the passed component is not null and if it's new to the tree. This operation can be used for
+ * determining if attributes should be wired to the component.
+ *
+ * @param component
+ * the component you wish to modify
+ * @return true if it's new
+ */
+ public static boolean isNew(UIComponent component)
+ {
+ return component != null && component.getParent() == null;
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConvertHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConvertHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConvertHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ConvertHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,157 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.io.IOException;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.view.facelets.ConverterConfig;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+
+import org.apache.myfaces.view.facelets.tag.MetaTagHandlerImpl;
+
+/**
+ * Handles setting a Converter instance on a ValueHolder. Will wire all attributes set to the Converter instance
+ * created/fetched. Uses the "binding" attribute for grabbing instances to apply attributes to. <p/> Will only
+ * set/create Converter is the passed UIComponent's parent is null, signifying that it wasn't restored from an existing
+ * tree.
+ *
+ * @see javax.faces.webapp.ConverterELTag
+ * @see javax.faces.convert.Converter
+ * @see javax.faces.component.ValueHolder
+ * @author Jacob Hookom
+ * @version $Id: ConvertHandler.java,v 1.4 2008/07/13 19:01:46 rlubke Exp $
+ */
+public class ConvertHandler extends MetaTagHandlerImpl
+{
+
+ private final TagAttribute binding;
+
+ private String converterId;
+
+ /**
+ * @param config
+ * @deprecated
+ */
+ public ConvertHandler(TagConfig config)
+ {
+ super(config);
+ this.binding = this.getAttribute("binding");
+ this.converterId = null;
+ }
+
+ public ConvertHandler(ConverterConfig config)
+ {
+ this((TagConfig) config);
+ this.converterId = config.getConverterId();
+ }
+
+ /**
+ * Set Converter instance on parent ValueHolder if it's not being restored.
+ * <ol>
+ * <li>Cast to ValueHolder</li>
+ * <li>If "binding" attribute was specified, fetch/create and re-bind to expression.</li>
+ * <li>Otherwise, call {@link #createConverter(FaceletContext) createConverter}.</li>
+ * <li>Call {@link ObjectHandler#setAttributes(FaceletContext, Object) setAttributes} on Converter instance.</li>
+ * <li>Set the Converter on the ValueHolder</li>
+ * <li>If the ValueHolder has a localValue, convert it and set the value</li>
+ * </ol>
+ *
+ * @see ValueHolder
+ * @see Converter
+ * @see #createConverter(FaceletContext)
+ * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ */
+ public final void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException,
+ FaceletException, ELException
+ {
+ if (parent == null || !(parent instanceof ValueHolder))
+ {
+ throw new TagException(this.tag, "Parent not an instance of ValueHolder: " + parent);
+ }
+
+ // only process if it's been created
+ if (parent.getParent() == null)
+ {
+ // cast to a ValueHolder
+ ValueHolder vh = (ValueHolder) parent;
+ ValueExpression ve = null;
+ Converter c = null;
+ if (this.binding != null)
+ {
+ ve = this.binding.getValueExpression(ctx, Converter.class);
+ c = (Converter) ve.getValue(ctx);
+ }
+ if (c == null)
+ {
+ c = this.createConverter(ctx);
+ if (ve != null)
+ {
+ ve.setValue(ctx, c);
+ }
+ }
+ if (c == null)
+ {
+ throw new TagException(this.tag, "No Converter was created");
+ }
+ this.setAttributes(ctx, c);
+ vh.setConverter(c);
+ Object lv = vh.getLocalValue();
+ FacesContext faces = ctx.getFacesContext();
+ if (lv instanceof String)
+ {
+ vh.setValue(c.getAsObject(faces, parent, (String) lv));
+ }
+ }
+ }
+
+ /**
+ * Create a Converter instance
+ *
+ * @param ctx
+ * FaceletContext to use
+ * @return Converter instance, cannot be null
+ */
+ protected Converter createConverter(FaceletContext ctx)
+ {
+ if (this.converterId == null)
+ {
+ throw new TagException(
+ this.tag,
+ "Default behavior invoked of requiring a converter-id passed in the constructor, must override ConvertHandler(ConverterConfig)");
+ }
+ return ctx.getFacesContext().getApplication().createConverter(this.converterId);
+ }
+
+ protected MetaRuleset createMetaRuleset(Class<?> type)
+ {
+ return super.createMetaRuleset(type).ignore("binding");
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/EditableValueHolderRule.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/EditableValueHolderRule.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/EditableValueHolderRule.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/EditableValueHolderRule.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.MethodExpressionValueChangeListener;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.validator.MethodExpressionValidator;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ * @author Jacob Hookom
+ * @version $Id: EditableValueHolderRule.java,v 1.3 2008/07/13 19:01:46 rlubke Exp $
+ */
+public final class EditableValueHolderRule extends MetaRule
+{
+
+ final static class LiteralValidatorMetadata extends Metadata
+ {
+
+ private final String validatorId;
+
+ public LiteralValidatorMetadata(String validatorId)
+ {
+ this.validatorId = validatorId;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((EditableValueHolder) instance).addValidator(ctx.getFacesContext().getApplication()
+ .createValidator(this.validatorId));
+ }
+ }
+
+ final static class ValueChangedExpressionMetadata extends Metadata
+ {
+ private final TagAttribute attr;
+
+ public ValueChangedExpressionMetadata(TagAttribute attr)
+ {
+ this.attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((EditableValueHolder) instance).addValueChangeListener(new MethodExpressionValueChangeListener(this.attr
+ .getMethodExpression(ctx, null, VALUECHANGE_SIG)));
+ }
+ }
+
+ final static class ValidatorExpressionMetadata extends Metadata
+ {
+ private final TagAttribute attr;
+
+ public ValidatorExpressionMetadata(TagAttribute attr)
+ {
+ this.attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((EditableValueHolder) instance).addValidator(new MethodExpressionValidator(this.attr
+ .getMethodExpression(ctx, null, VALIDATOR_SIG)));
+ }
+ }
+
+ private final static Class<?>[] VALIDATOR_SIG = new Class[] { FacesContext.class, UIComponent.class, Object.class };
+
+ private final static Class<?>[] VALUECHANGE_SIG = new Class[] { ValueChangeEvent.class };
+
+ public final static EditableValueHolderRule Instance = new EditableValueHolderRule();
+
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta)
+ {
+
+ if (meta.isTargetInstanceOf(EditableValueHolder.class))
+ {
+
+ if ("validator".equals(name))
+ {
+ if (attribute.isLiteral())
+ {
+ return new LiteralValidatorMetadata(attribute.getValue());
+ }
+ else
+ {
+ return new ValidatorExpressionMetadata(attribute);
+ }
+ }
+
+ if ("valueChangeListener".equals(name))
+ {
+ return new ValueChangedExpressionMetadata(attribute);
+ }
+
+ }
+ return null;
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidateHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidateHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidateHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValidateHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,138 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.io.IOException;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.validator.Validator;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.ValidatorConfig;
+
+import org.apache.myfaces.view.facelets.tag.MetaTagHandlerImpl;
+
+/**
+ * Handles setting a Validator instance on a EditableValueHolder. Will wire all attributes set to the Validator instance
+ * created/fetched. Uses the "binding" attribute for grabbing instances to apply attributes to. <p/> Will only
+ * set/create Validator is the passed UIComponent's parent is null, signifying that it wasn't restored from an existing
+ * tree.
+ *
+ * @author Jacob Hookom
+ * @version $Id: ValidateHandler.java,v 1.4 2008/07/13 19:01:46 rlubke Exp $
+ */
+public class ValidateHandler extends MetaTagHandlerImpl
+{
+
+ private final TagAttribute binding;
+
+ private String validatorId;
+
+ /**
+ *
+ * @param config
+ * @deprecated
+ */
+ public ValidateHandler(TagConfig config)
+ {
+ super(config);
+ this.binding = this.getAttribute("binding");
+ }
+
+ public ValidateHandler(ValidatorConfig config)
+ {
+ this((TagConfig) config);
+ this.validatorId = config.getValidatorId();
+ }
+
+ /**
+ * TODO
+ *
+ * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ */
+ public final void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException,
+ FaceletException, ELException
+ {
+
+ if (parent == null || !(parent instanceof EditableValueHolder))
+ {
+ throw new TagException(this.tag, "Parent not an instance of EditableValueHolder: " + parent);
+ }
+
+ // only process if it's been created
+ if (parent.getParent() == null)
+ {
+ // cast to a ValueHolder
+ EditableValueHolder evh = (EditableValueHolder) parent;
+ ValueExpression ve = null;
+ Validator v = null;
+ if (this.binding != null)
+ {
+ ve = this.binding.getValueExpression(ctx, Validator.class);
+ v = (Validator) ve.getValue(ctx);
+ }
+ if (v == null)
+ {
+ v = this.createValidator(ctx);
+ if (ve != null)
+ {
+ ve.setValue(ctx, v);
+ }
+ }
+ if (v == null)
+ {
+ throw new TagException(this.tag, "No Validator was created");
+ }
+ this.setAttributes(ctx, v);
+ evh.addValidator(v);
+ }
+ }
+
+ /**
+ * Template method for creating a Validator instance
+ *
+ * @param ctx
+ * FaceletContext to use
+ * @return a new Validator instance
+ */
+ protected Validator createValidator(FaceletContext ctx)
+ {
+ if (this.validatorId == null)
+ {
+ throw new TagException(
+ this.tag,
+ "Default behavior invoked of requiring a validator-id passed in the constructor, must override ValidateHandler(ValidatorConfig)");
+ }
+ return ctx.getFacesContext().getApplication().createValidator(this.validatorId);
+ }
+
+ protected MetaRuleset createMetaRuleset(Class<?> type)
+ {
+ return super.createMetaRuleset(type).ignore("binding");
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValueHolderRule.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValueHolderRule.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValueHolderRule.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ValueHolderRule.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,137 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.convert.Converter;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ *
+ * @author Jacob Hookom
+ * @version $Id: ValueHolderRule.java,v 1.4 2008/07/13 19:01:46 rlubke 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 DynamicConverterMetadata2 extends Metadata
+ {
+
+ private final TagAttribute attr;
+
+ public DynamicConverterMetadata2(TagAttribute attr)
+ {
+ this.attr = attr;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ ((UIComponent) instance).setValueExpression("converter", attr.getValueExpression(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));
+ }
+ }
+
+ 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 DynamicConverterMetadata2(attribute);
+ }
+ }
+
+ if ("value".equals(name))
+ {
+ if (attribute.isLiteral())
+ {
+ return new LiteralValueMetadata(attribute.getValue());
+ }
+ else
+ {
+ return new DynamicValueExpressionMetadata(attribute);
+ }
+ }
+ }
+ return null;
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ActionListenerHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,170 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.ActionSource;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributeException;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.TagHandler;
+
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
+import org.apache.myfaces.view.facelets.util.ReflectionUtil;
+
+/**
+ * Register an ActionListener instance on the UIComponent associated with the closest parent UIComponent custom action.
+ * <p/> See <a target="_new"
+ * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/actionListener.html">tag documentation</a>.
+ *
+ * @see javax.faces.event.ActionListener
+ * @see javax.faces.component.ActionSource
+ * @author Jacob Hookom
+ * @version $Id: ActionListenerHandler.java,v 1.7 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class ActionListenerHandler extends TagHandler
+{
+
+ private final static class LazyActionListener implements ActionListener, Serializable
+ {
+
+ private static final long serialVersionUID = -9202120013153262119L;
+
+ private final String type;
+ private final ValueExpression binding;
+
+ public LazyActionListener(String type, ValueExpression binding)
+ {
+ this.type = type;
+ this.binding = binding;
+ }
+
+ public void processAction(ActionEvent event) throws AbortProcessingException
+ {
+ ActionListener instance = null;
+ FacesContext faces = FacesContext.getCurrentInstance();
+ if (faces == null)
+ {
+ return;
+ }
+ if (this.binding != null)
+ {
+ instance = (ActionListener) binding.getValue(faces.getELContext());
+ }
+ if (instance == null && this.type != null)
+ {
+ try
+ {
+ instance = (ActionListener) ReflectionUtil.forName(this.type).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new AbortProcessingException("Couldn't Lazily instantiate ValueChangeListener", e);
+ }
+ if (this.binding != null)
+ {
+ binding.setValue(faces.getELContext(), instance);
+ }
+ }
+ if (instance != null)
+ {
+ instance.processAction(event);
+ }
+ }
+ }
+
+ private final TagAttribute binding;
+
+ private final String listenerType;
+
+ /**
+ * @param config
+ */
+ public ActionListenerHandler(TagConfig config)
+ {
+ super(config);
+ this.binding = this.getAttribute("binding");
+ TagAttribute type = this.getAttribute("type");
+ if (type != null)
+ {
+ if (!type.isLiteral())
+ {
+ throw new TagAttributeException(type, "Must be a literal class name of type ActionListener");
+ }
+ else
+ {
+ // test it out
+ try
+ {
+ ReflectionUtil.forName(type.getValue());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new TagAttributeException(type, "Couldn't qualify ActionListener", e);
+ }
+ }
+ this.listenerType = type.getValue();
+ }
+ else
+ {
+ this.listenerType = null;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
+ ELException
+ {
+ if (parent instanceof ActionSource)
+ {
+ if (ComponentSupport.isNew(parent))
+ {
+ ActionSource as = (ActionSource) parent;
+ ValueExpression b = null;
+ if (this.binding != null)
+ {
+ b = this.binding.getValueExpression(ctx, ActionListener.class);
+ }
+ ActionListener listener = new LazyActionListener(this.listenerType, b);
+ as.addActionListener(listener);
+ }
+ }
+ else
+ {
+ throw new TagException(this.tag, "Parent is not of type ActionSource, type is: " + parent);
+ }
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/AttributeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/AttributeHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/AttributeHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/AttributeHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,89 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import java.io.IOException;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagException;
+import javax.faces.view.facelets.TagHandler;
+
+/**
+ * Sets the specified name and attribute on the parent UIComponent. If the "value" specified is not a literal, it will
+ * instead set the ValueExpression on the UIComponent. <p /> See <a target="_new"
+ * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/attribute.html">tag documentation</a>.
+ *
+ * @see javax.faces.component.UIComponent#getAttributes()
+ * @see javax.faces.component.UIComponent#setValueExpression(java.lang.String, javax.el.ValueExpression)
+ * @author Jacob Hookom
+ * @version $Id: AttributeHandler.java,v 1.3 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class AttributeHandler extends TagHandler
+{
+ private final TagAttribute _name;
+
+ private final TagAttribute _value;
+
+ /**
+ * @param config
+ */
+ public AttributeHandler(TagConfig config)
+ {
+ super(config);
+ _name = getRequiredAttribute("name");
+ _value = getRequiredAttribute("value");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
+ */
+ public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
+ ELException
+ {
+ if (parent == null)
+ {
+ throw new TagException(this.tag, "Parent UIComponent was null");
+ }
+
+ // only process if the parent is new to the tree
+ if (parent.getParent() == null)
+ {
+ String n = _name.getValue(ctx);
+ if (!parent.getAttributes().containsKey(n))
+ {
+ if (_value.isLiteral())
+ {
+ parent.getAttributes().put(n, _value.getValue());
+ }
+ else
+ {
+ parent.setValueExpression(n, _value.getValueExpression(ctx, Object.class));
+ }
+ }
+ }
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDateTimeHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDateTimeHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDateTimeHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDateTimeHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,146 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import java.util.TimeZone;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.convert.Converter;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.view.facelets.ConverterConfig;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagAttributeException;
+
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
+import org.apache.myfaces.view.facelets.tag.jsf.ConvertHandler;
+
+/**
+ * Register a DateTimeConverter instance on the UIComponent associated with the closest parent UIComponent custom
+ * action. <p/> See <a target="_new"
+ * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/convertDateTime.html">tag documentation</a>.
+ *
+ * @author Jacob Hookom
+ * @version $Id: ConvertDateTimeHandler.java,v 1.6 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class ConvertDateTimeHandler extends ConvertHandler
+{
+
+ private final TagAttribute dateStyle;
+
+ private final TagAttribute locale;
+
+ private final TagAttribute pattern;
+
+ private final TagAttribute timeStyle;
+
+ private final TagAttribute timeZone;
+
+ private final TagAttribute type;
+
+ /**
+ * @param config
+ */
+ public ConvertDateTimeHandler(ConverterConfig config)
+ {
+ super(config);
+ this.dateStyle = this.getAttribute("dateStyle");
+ this.locale = this.getAttribute("locale");
+ this.pattern = this.getAttribute("pattern");
+ this.timeStyle = this.getAttribute("timeStyle");
+ this.timeZone = this.getAttribute("timeZone");
+ this.type = this.getAttribute("type");
+ }
+
+ /**
+ * Returns a new DateTimeConverter
+ *
+ * @see DateTimeConverter
+ * @see org.apache.myfaces.view.facelets.tag.jsf.ConvertHandler#createConverter(javax.faces.view.facelets.FaceletContext)
+ */
+ protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException
+ {
+ return ctx.getFacesContext().getApplication().createConverter(DateTimeConverter.CONVERTER_ID);
+
+ }
+
+ /**
+ * Implements tag spec, see taglib documentation.
+ *
+ * @see org.apache.myfaces.view.facelets.tag.ObjectHandler#setAttributes(javax.faces.view.facelets.FaceletContext, java.lang.Object)
+ */
+ protected void setAttributes(FaceletContext ctx, Object obj)
+ {
+ DateTimeConverter c = (DateTimeConverter) obj;
+ if (this.locale != null)
+ {
+ c.setLocale(ComponentSupport.getLocale(ctx, this.locale));
+ }
+ if (this.pattern != null)
+ {
+ c.setPattern(this.pattern.getValue(ctx));
+ }
+ else
+ {
+ if (this.type != null)
+ {
+ c.setType(this.type.getValue(ctx));
+ }
+ if (this.dateStyle != null)
+ {
+ c.setDateStyle(this.dateStyle.getValue(ctx));
+ }
+ if (this.timeStyle != null)
+ {
+ c.setTimeStyle(this.timeStyle.getValue(ctx));
+ }
+ }
+
+ if (this.timeZone != null)
+ {
+ Object t = this.timeZone.getObject(ctx);
+ if (t != null)
+ {
+ if (t instanceof TimeZone)
+ {
+ c.setTimeZone((TimeZone) t);
+ }
+ else if (t instanceof String)
+ {
+ TimeZone tz = TimeZone.getTimeZone((String) t);
+ c.setTimeZone(tz);
+ }
+ else
+ {
+ throw new TagAttributeException(this.tag, this.timeZone,
+ "Illegal TimeZone, must evaluate to either a java.util.TimeZone or String, is type: "
+ + t.getClass());
+ }
+ }
+ }
+ }
+
+ protected MetaRuleset createMetaRuleset(Class<?> type)
+ {
+ return super.createMetaRuleset(type).ignoreAll();
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDelegateHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDelegateHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDelegateHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertDelegateHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.convert.Converter;
+import javax.faces.view.facelets.ConverterConfig;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.apache.myfaces.view.facelets.tag.jsf.ConvertHandler;
+
+/**
+ * Register a named Converter instance on the UIComponent associated with the closest parent UIComponent custom action.
+ * <p/> See <a target="_new" href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/converter.html">tag
+ * documentation</a>.
+ *
+ * @author Jacob Hookom
+ * @version $Id: ConvertDelegateHandler.java,v 1.4 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class ConvertDelegateHandler extends ConvertHandler
+{
+
+ private final TagAttribute converterId;
+
+ /**
+ * @param config
+ */
+ public ConvertDelegateHandler(ConverterConfig config)
+ {
+ super(config);
+ this.converterId = this.getRequiredAttribute("converterId");
+ }
+
+ /**
+ * Uses the specified "converterId" to pull an instance from the Application
+ *
+ * @see javax.faces.application.Application#createComponent(java.lang.String)
+ * @see org.apache.myfaces.view.facelets.tag.jsf.ConverterHandler#createConverter(javax.faces.view.facelets.FaceletContext)
+ */
+ protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException
+ {
+ return ctx.getFacesContext().getApplication().createConverter(this.converterId.getValue(ctx));
+ }
+
+ protected MetaRuleset createMetaRuleset(Class<?> type)
+ {
+ return super.createMetaRuleset(type).ignoreAll();
+ }
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertNumberHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertNumberHandler.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertNumberHandler.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ConvertNumberHandler.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,87 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import javax.el.ELException;
+import javax.faces.FacesException;
+import javax.faces.convert.Converter;
+import javax.faces.convert.NumberConverter;
+import javax.faces.view.facelets.ConverterConfig;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.FaceletException;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
+import org.apache.myfaces.view.facelets.tag.jsf.ConvertHandler;
+
+/**
+ * Register a NumberConverter instance on the UIComponent associated with the closest parent UIComponent custom action.
+ * <p/> See <a target="_new"
+ * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/convertNumber.html">tag documentation</a>.
+ *
+ * @author Jacob Hookom
+ * @version $Id: ConvertNumberHandler.java,v 1.4 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class ConvertNumberHandler extends ConvertHandler
+{
+
+ private final TagAttribute locale;
+
+ /**
+ * @param config
+ */
+ public ConvertNumberHandler(ConverterConfig config)
+ {
+ super(config);
+ this.locale = this.getAttribute("locale");
+ }
+
+ /**
+ * Returns a new NumberConverter
+ *
+ * @see NumberConverter
+ * @see org.apache.myfaces.view.facelets.tag.jsf.ConverterHandler#createConverter(javax.faces.view.facelets.FaceletContext)
+ */
+ protected Converter createConverter(FaceletContext ctx) throws FacesException, ELException, FaceletException
+ {
+ return ctx.getFacesContext().getApplication().createConverter(NumberConverter.CONVERTER_ID);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.myfaces.view.facelets.tag.ObjectHandler#setAttributes(javax.faces.view.facelets.FaceletContext, java.lang.Object)
+ */
+ protected void setAttributes(FaceletContext ctx, Object obj)
+ {
+ super.setAttributes(ctx, obj);
+ NumberConverter c = (NumberConverter) obj;
+ if (this.locale != null)
+ {
+ c.setLocale(ComponentSupport.getLocale(ctx, this.locale));
+ }
+ }
+
+ protected MetaRuleset createMetaRuleset(Class<?> type)
+ {
+ return super.createMetaRuleset(type).ignore("locale");
+ }
+
+}
Added: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java?rev=761982&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/CoreLibrary.java Sat Apr 4 18:44:59 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.view.facelets.tag.jsf.core;
+
+import javax.faces.component.UIParameter;
+import javax.faces.component.UISelectItem;
+import javax.faces.component.UISelectItems;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.convert.NumberConverter;
+import javax.faces.validator.DoubleRangeValidator;
+import javax.faces.validator.LengthValidator;
+import javax.faces.validator.LongRangeValidator;
+import javax.faces.validator.RegexValidator;
+
+import org.apache.myfaces.view.facelets.tag.AbstractTagLibrary;
+
+/**
+ * For Tag details, see JSF Core <a target="_new"
+ * href="http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/tlddocs/f/tld-summary.html">taglib documentation</a>.
+ *
+ * @author Jacob Hookom
+ * @version $Id: CoreLibrary.java,v 1.13 2008/07/13 19:01:44 rlubke Exp $
+ */
+public final class CoreLibrary extends AbstractTagLibrary
+{
+
+ public final static String Namespace = "http://java.sun.com/jsf/core";
+
+ public final static CoreLibrary Instance = new CoreLibrary();
+
+ public CoreLibrary()
+ {
+ super(Namespace);
+
+ this.addTagHandler("actionListener", ActionListenerHandler.class);
+
+ this.addTagHandler("attribute", AttributeHandler.class);
+
+ this.addConverter("convertDateTime", DateTimeConverter.CONVERTER_ID, ConvertDateTimeHandler.class);
+
+ this.addConverter("convertNumber", NumberConverter.CONVERTER_ID, ConvertNumberHandler.class);
+
+ this.addConverter("converter", null, ConvertDelegateHandler.class);
+
+ this.addTagHandler("facet", FacetHandler.class);
+
+ this.addTagHandler("loadBundle", LoadBundleHandler.class);
+
+ this.addComponent("param", UIParameter.COMPONENT_TYPE, null);
+
+ this.addTagHandler("phaseListener", PhaseListenerHandler.class);
+
+ this.addComponent("selectItem", UISelectItem.COMPONENT_TYPE, null);
+
+ this.addComponent("selectItems", UISelectItems.COMPONENT_TYPE, null);
+
+ this.addTagHandler("setPropertyActionListener", SetPropertyActionListenerHandler.class);
+
+ this.addComponent("subview", "javax.faces.NamingContainer", null);
+
+ this.addValidator("validateLength", LengthValidator.VALIDATOR_ID);
+
+ this.addValidator("validateLongRange", LongRangeValidator.VALIDATOR_ID);
+
+ this.addValidator("validateDoubleRange", DoubleRangeValidator.VALIDATOR_ID);
+
+ this.addValidator("validateRegex", RegexValidator.VALIDATOR_ID);
+
+ this.addValidator("validator", null, ValidateDelegateHandler.class);
+
+ this.addTagHandler("valueChangeListener", ValueChangeListenerHandler.class);
+
+ this.addTagHandler("view", ViewHandler.class);
+
+ this.addComponent("verbatim", "javax.faces.HtmlOutputText", "javax.faces.Text", VerbatimHandler.class);
+ }
+}