myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1099839 - in /myfaces/tomahawk/trunk: core/src/main/java/org/apache/myfaces/validator/ core/src/main/resources/META-INF/ core12/src/main/java/org/apache/myfaces/validator/ core12/src/main/resources/META-INF/ core20/src/main/java/org/apache...
Date Thu, 05 May 2011 15:22:42 GMT
Author: lu4242
Date: Thu May  5 15:22:41 2011
New Revision: 1099839

URL: http://svn.apache.org/viewvc?rev=1099839&view=rev
Log:
TOMAHAWK-1573 <t:validateEqual> throws java.lang.NullPointerException: expr

Added:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/AbstractEqualValidator.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
Removed:
    myfaces/tomahawk/trunk/core/src/main/resources/META-INF/facelets-taglib.vm
    myfaces/tomahawk/trunk/core12/src/main/resources/META-INF/facelets-taglib.vm
    myfaces/tomahawk/trunk/core20/src/main/resources/META-INF/tld-facelets-tomahawk20.vm
Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
    myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/validate.xhtml

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBase.java?rev=1099839&r1=1099838&r2=1099839&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
Thu May  5 15:22:41 2011
@@ -37,6 +37,7 @@ import org.apache.myfaces.tomahawk.util.
  * @JSFValidator
  *   configExcluded = "true"
  *   tagClass = "org.apache.myfaces.validator.ValidatorBaseTag"
+ *   tagHandler = "org.apache.myfaces.validator.ValidatorBaseTagHandler"
  */
 public abstract class ValidatorBase implements StateHolder, Validator {
 

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
(added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
Thu May  5 15:22:41 2011
@@ -0,0 +1,42 @@
+/*
+ * 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.validator;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ValidateHandler;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+public class ValidatorBaseTagHandler extends ValidateHandler
+{
+
+    public ValidatorBaseTagHandler(ValidatorConfig config)
+    {
+        super(config);
+    }
+
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        MetaRuleset ruleSet = super.createMetaRuleset(type);
+        
+        //Add rule to handle EL expressions
+        ruleSet.addRule(_ValidatorRule.Instance);
+        
+        return ruleSet;
+    }
+}

Added: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
(added)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
Thu May  5 15:22:41 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.validator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+final class _ValidatorRule extends MetaRule {
+
+    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) {
+            ((ValidatorBase) instance).setValueBinding(this.name,
+                    new LegacyValueBinding(this.attr.getValueExpression(ctx,
+                            this.type)));
+        }
+
+    }
+
+    public final static _ValidatorRule Instance = new _ValidatorRule();
+
+    public _ValidatorRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(ValidatorBase.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 ValueBindingMetadata(name, type, attribute);
+            }
+        }
+        return null;
+    }
+}

Modified: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBase.java?rev=1099839&r1=1099838&r2=1099839&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
(original)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBase.java
Thu May  5 15:22:41 2011
@@ -43,7 +43,8 @@ import org.apache.myfaces.tomahawk.util.
  */
 @JSFValidator(
    configExcluded = true,
-   tagClass = "org.apache.myfaces.validator.ValidatorBaseTag")
+   tagClass = "org.apache.myfaces.validator.ValidatorBaseTag",
+   tagHandler = "org.apache.myfaces.validator.ValidatorBaseTagHandler")
 public abstract class ValidatorBase implements StateHolder, Validator {
 
     private String _summaryMessage = null;

Added: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
(added)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
Thu May  5 15:22:41 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.validator;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ValidateHandler;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+public class ValidatorBaseTagHandler extends ValidateHandler
+{
+
+    public ValidatorBaseTagHandler(ValidatorConfig config)
+    {
+        super(config);
+        // TODO Auto-generated constructor stub
+    }
+
+    @Override
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        MetaRuleset ruleSet = super.createMetaRuleset(type);
+        
+        //Add rule to handle EL expressions
+        ruleSet.addRule(_ValidatorRule.Instance);
+        
+        return ruleSet;
+    }
+}

Added: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
(added)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
Thu May  5 15:22:41 2011
@@ -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.validator;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+
+final class _ValidatorRule extends MetaRule {
+
+    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) {
+            ((ValidatorBase) 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) {
+            ((ValidatorBase) instance).setValueBinding(this.name,
+                    new LegacyValueBinding(this.attr.getValueExpression(ctx,
+                            this.type)));
+        }
+
+    }*/
+
+    public final static _ValidatorRule Instance = new _ValidatorRule();
+
+    public _ValidatorRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(ValidatorBase.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);
+                //}
+            }
+        }
+        return null;
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/AbstractEqualValidator.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/AbstractEqualValidator.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/AbstractEqualValidator.java
(added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/equalvalidator/AbstractEqualValidator.java
Thu May  5 15:22:41 2011
@@ -0,0 +1,258 @@
+/*
+ * 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.custom.equalvalidator;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.el.ValueBinding;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.Renderer;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFValidator;
+import org.apache.myfaces.validator.ValidatorBase;
+
+
+/**
+ * A custom validator for validations against foreign component values. 
+ * 
+ * Unless otherwise specified, all attributes accept static values or EL expressions.
+ * 
+ * @since 1.1.7
+ * @deprecated use myfaces commons mcv:validateEqual instead
+ * @author mwessendorf (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFValidator(
+   name = "t:validateEqual",
+   clazz = "org.apache.myfaces.custom.equalvalidator.EqualValidator",
+   tagClass = "org.apache.myfaces.custom.equalvalidator.ValidateEqualTag",
+   serialuidtag = "-3249115551944863108L")
+public abstract class AbstractEqualValidator extends ValidatorBase {
+
+    /**
+     * <p>The standard converter id for this converter.</p>
+     */
+    public static final String     VALIDATOR_ID        = "org.apache.myfaces.validator.Equal";
+
+    /**
+     * <p>The message identifier of the {@link FacesMessage} to be created if
+     * the equal_for check fails.</p>
+     */
+    public static final String EQUAL_MESSAGE_ID = "org.apache.myfaces.Equal.INVALID";
+
+    public AbstractEqualValidator(){
+    }
+
+  // -------------------------------------------------------- ValidatorIF
+    public void validate(
+        FacesContext facesContext,
+        UIComponent uiComponent,
+        Object value)
+        throws ValidatorException {
+
+        if (facesContext == null) throw new NullPointerException("facesContext");
+        if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+        if (value == null)
+        {
+            return;
+        }
+
+        String forId = getFor();
+        forId = (forId != null && forId.length() > 0) ? forId : getForId();
+        if (forId == null) {
+            throw new FacesException("No id set to compare. Use 'for' in jsp mode and 'forId'
in facelets mode");
+        }
+        UIComponent foreignComp = uiComponent.getParent().findComponent(forId);
+        if(foreignComp==null)
+            throw new FacesException("Unable to find component '" + forId + "' (calling findComponent
on component '" + uiComponent.getId() + "')");
+        if(false == foreignComp instanceof EditableValueHolder)
+            throw new FacesException("Component '" + foreignComp.getId() + "' does not implement
EditableValueHolder");
+        EditableValueHolder foreignEditableValueHolder = (EditableValueHolder) foreignComp;
+
+        if (foreignEditableValueHolder.isRequired() && foreignEditableValueHolder.getValue()==
null ) {
+            return;
+        }
+        
+        Object foreignValue;
+        if (foreignEditableValueHolder.isValid())
+        {
+            foreignValue = foreignEditableValueHolder.getValue();
+        }
+        else
+        {
+            try 
+            {
+                foreignValue = getConvertedValueNonValid(facesContext, foreignComp);
+            }
+            catch(ConverterException e)
+            {
+                /*
+                 * If the value cannot be converted this should return,
+                 * because does not have sense compare one
+                 * foreign invalid value with other value.
+                 * this force end the validation but do not continue
+                 * with the next phases, because the converter
+                 * of the foreign component fails and show a validation error.
+                 */
+                return;
+            }
+        }
+
+        // Don't perform validation if the foreign value is null
+        if (null == foreignValue)
+        {
+            return;
+        }
+        
+
+        Object[] args = {value.toString(),(foreignValue==null) ? foreignComp.getId():foreignValue.toString()};
+
+        if(foreignEditableValueHolder.getValue()==null || !foreignValue.toString().equals(value.toString())
 )
+        {
+            throw new ValidatorException(getFacesMessage(EQUAL_MESSAGE_ID, args));
+        }
+
+    }
+    
+    // ---------------- Borrowed to convert foreign submitted values
+
+    protected Renderer getRenderer(FacesContext context, UIComponent foreignComponent)
+    {
+        if (context == null) throw new NullPointerException("context");
+        String rendererType = foreignComponent.getRendererType();
+        if (rendererType == null) return null;
+        String renderKitId = context.getViewRoot().getRenderKitId();
+        RenderKitFactory rkf = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        RenderKit renderKit = rkf.getRenderKit(context, renderKitId);
+        Renderer renderer = renderKit.getRenderer(foreignComponent.getFamily(), rendererType);
+        if (renderer == null)
+        {
+            getFacesContext().getExternalContext().log("No Renderer found for component "
+ foreignComponent + " (component-family=" + foreignComponent.getFamily() + ", renderer-type="
+ rendererType + ")");
+        }
+        return renderer;
+    }
+
+    protected Converter findUIOutputConverter(FacesContext facesContext, UIComponent component)
+    {
+        Converter converter = ((EditableValueHolder)component).getConverter();
+        if (converter != null) return converter;
+
+        //Try to find out by value binding
+        ValueBinding vb = component.getValueBinding("value");
+        if (vb == null) return null;
+
+        Class valueType = vb.getType(facesContext);
+        if (valueType == null) return null;
+
+        if (String.class.equals(valueType)) return null;    //No converter needed for String
type
+        if (Object.class.equals(valueType)) return null;    //There is no converter for Object
class
+
+        try
+        {
+            return facesContext.getApplication().createConverter(valueType);
+        }
+        catch (FacesException e)
+        {
+            getFacesContext().getExternalContext().log("No Converter for type " + valueType.getName()
+ " found", e);
+            return null;
+        }
+    }
+
+
+    // --------------------- borrowed and modified from UIInput ------------
+
+    protected Object getConvertedValueNonValid(FacesContext facesContext, UIComponent component)
+        throws ConverterException
+    {
+        Object componentValueObject;
+        Object submittedValue = ((EditableValueHolder) component).getSubmittedValue();
+        if (submittedValue == null)
+        {
+            componentValueObject = null;
+        }
+        else
+        {
+            Renderer renderer = getRenderer(facesContext, component);
+            if (renderer != null)
+            {
+                componentValueObject = renderer.getConvertedValue(facesContext, component,
submittedValue);
+            }
+            else if (submittedValue instanceof String)
+            {
+                Converter converter = findUIOutputConverter(facesContext, component);
+                if (converter != null)
+                {
+                    componentValueObject = converter.getAsObject(facesContext, component,
(String)submittedValue);
+                }
+                else
+                {
+                    componentValueObject = submittedValue;
+                }
+            }else{
+                componentValueObject = submittedValue;
+            }
+        }
+        return componentValueObject;
+    }
+        
+    // -------------------------------------------------------- GETTER & SETTER
+
+    /**
+     * the id of the foreign component, which is needed for the validation
+     * 
+     * In JSF 2.0 facelets mode is used to identify the components this 
+     * validator should be applied to when using composite components.
+     * Please use forId in that case instead.
+     * 
+     * @JSFProperty
+     * @return the foreign component_id, on which a value should be validated
+     */
+    public abstract String getFor();
+    
+    /**
+     * @param string the foreign component_id, on which a value should be validated
+     */
+    public abstract void setFor(String string);
+    
+    /**
+     * the id of the foreign component, which is needed for the validation
+     * 
+     * @return
+     */
+    @JSFProperty(faceletsOnly=true)
+    public abstract String getForId();
+    
+    /**
+     * the id of the foreign component, which is needed for the validation
+     * 
+     * @param string
+     */
+    public abstract void setForId(String string);
+
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
(added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/ValidatorBaseTagHandler.java
Thu May  5 15:22:41 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.validator;
+
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.ValidatorConfig;
+import javax.faces.view.facelets.ValidatorHandler;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
+
+@JSFFaceletTag
+public class ValidatorBaseTagHandler extends ValidatorHandler
+{
+
+    public ValidatorBaseTagHandler(ValidatorConfig config)
+    {
+        super(config);
+    }
+
+    @Override
+    protected MetaRuleset createMetaRuleset(Class type)
+    {
+        MetaRuleset ruleSet = super.createMetaRuleset(type);
+        
+        //Add rule to handle EL expressions
+        ruleSet.addRule(_ValidatorRule.Instance);
+        
+        return ruleSet;
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java?rev=1099839&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
(added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/validator/_ValidatorRule.java
Thu May  5 15:22:41 2011
@@ -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.validator;
+
+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;
+
+final class _ValidatorRule extends MetaRule {
+
+    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) {
+            ((ValidatorBase) 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) {
+            ((ValidatorBase) instance).setValueBinding(this.name,
+                    new LegacyValueBinding(this.attr.getValueExpression(ctx,
+                            this.type)));
+        }
+
+    }*/
+
+    public final static _ValidatorRule Instance = new _ValidatorRule();
+
+    public _ValidatorRule() {
+        super();
+    }
+
+    public Metadata applyRule(String name, TagAttribute attribute,
+            MetadataTarget meta) {
+        if (meta.isTargetInstanceOf(ValidatorBase.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);
+                //}
+            }
+        }
+        return null;
+    }
+}

Modified: myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/validate.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/validate.xhtml?rev=1099839&r1=1099838&r2=1099839&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/validate.xhtml (original)
+++ myfaces/tomahawk/trunk/examples/simple20/src/main/webapp/validate.xhtml Thu May  5 15:22:41
2011
@@ -66,7 +66,7 @@
 
                 <h:outputLabel for="equal2" value="#{example_messages['validate_equal']}2"/>
                 <h:inputText id="equal2" value="#{validateForm.equal2}" required="true">
-                    <t:validateEqual for="equal"
+                    <t:validateEqual forId="equal"
                                      summaryMessage='#{"Value {0} should equal {1}"}'
                                      detailMessage='#{"The value of this field, {0}, should
equal the value of that other field, {1}"}'/>
                 </h:inputText>



Mime
View raw message