myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r600199 - in /myfaces/core/trunk_1.2.x/impl/src/main: java/org/apache/myfaces/taglib/core/ resources/META-INF/
Date Sat, 01 Dec 2007 21:28:16 GMT
Author: lu4242
Date: Sat Dec  1 13:28:15 2007
New Revision: 600199

URL: http://svn.apache.org/viewvc?rev=600199&view=rev
Log:
fixes MYFACES-1741 JSR-252 Issue 21 - Provided an additional "binding" attribute for the core
Converter, Listener and Validator tags has wrong behaviour (make it compatible with jsf ri).

Added:
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
  (with props)
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
  (with props)
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
  (with props)
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
  (with props)
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
  (with props)
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
  (with props)
Modified:
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ActionListenerTag.java
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/GenericListenerTag.java
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValueChangeListenerTag.java
    myfaces/core/trunk_1.2.x/impl/src/main/resources/META-INF/myfaces_core.tld

Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ActionListenerTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ActionListenerTag.java?rev=600199&r1=600198&r2=600199&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ActionListenerTag.java
(original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ActionListenerTag.java
Sat Dec  1 13:28:15 2007
@@ -15,6 +15,7 @@
  */
 package org.apache.myfaces.taglib.core;
 
+import javax.el.ValueExpression;
 import javax.faces.component.ActionSource;
 import javax.faces.event.ActionListener;
 
@@ -36,5 +37,12 @@
     {
         actionSource.addActionListener(actionListener);
     }
+
+    protected ActionListener createDelegateListener(ValueExpression type,
+            ValueExpression binding)
+    {
+        return new DelegateActionListener(type,binding);
+    }
 }
+
 

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.taglib.core;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.webapp.ConverterELTag;
+import javax.servlet.jsp.JspException;
+
+/**
+ * Implementation of ConverterELTag
+ * 
+ * Implements the Tag class of f:converter
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ */
+public class ConverterImplTag extends ConverterELTag
+{
+
+    private static final long serialVersionUID = -4506829108081L;
+    private ValueExpression _converterId;
+    private ValueExpression _binding;
+    private String _converterIdString = null;
+
+    public ConverterImplTag()
+    {
+        super();
+    }
+
+    public void setConverterId(ValueExpression converterId)
+    {
+        _converterId = converterId;
+    }
+
+    public void setBinding(ValueExpression binding)
+    {
+        _binding = binding;
+    }
+
+    /**
+     * Use this method to specify the converterId programmatically.
+     *
+     * @param converterIdString
+     */
+    public void setConverterIdString(String converterIdString)
+    {
+        _converterIdString = converterIdString;
+    }
+
+    public void release()
+    {
+        super.release();
+        _converterId = null;
+        _binding = null;
+        _converterIdString = null;
+    }
+
+    protected Converter createConverter() throws JspException
+    {
+        if (_converterId != null && _converterId.isLiteralText())
+        {
+            this.createClassicConverter();
+        }
+        if (_converterIdString != null){
+            this.createClassicConverter();
+        }
+        
+        return new DelegateConverter(_converterId, _binding,
+                _converterIdString);
+    }
+
+    protected Converter createClassicConverter() throws JspException
+    {
+        Converter converter = null;
+
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ELContext elContext = facesContext.getELContext();
+
+        // try to create the converter from the binding expression first, and then from
+        // the converterId
+        if (_binding != null)
+        {
+            try
+            {
+                converter = (Converter) _binding.getValue(elContext);
+
+                if (converter != null)
+                {
+                    return converter;
+                }
+            }
+            catch (Exception e)
+            {
+                throw new JspException(
+                        "Exception creating converter using binding", e);
+            }
+        }
+
+        if ((_converterId != null) || (_converterIdString != null))
+        {
+            try
+            {
+                if (null != _converterIdString)
+                {
+                    converter = facesContext.getApplication().createConverter(
+                            _converterIdString);
+                }
+                else
+                {
+                    String converterId = (String) _converterId
+                            .getValue(elContext);
+                    converter = facesContext.getApplication().createConverter(
+                            converterId);
+                }
+
+                // with binding no converter was created, set its value with the converter
+                // created using the converterId
+                if (converter != null && _binding != null)
+                {
+                    _binding.setValue(elContext, converter);
+                }
+            }
+            catch (Exception e)
+            {
+                throw new JspException(
+                        "Exception creating converter with converterId: "
+                                + _converterId, e);
+            }
+        }
+
+        return converter;
+    }
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ConverterImplTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,162 @@
+/*
+ * 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.taglib.core;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+
+
+/**
+ * This class is used in conjunction with ActionListenerTag. 
+ * 
+ * When a tag like this is in a jsp page:
+ * 
+ * <f:actionListener binding="#{mybean}"/>
+ *  
+ *  or
+ *  
+ * <f:actionListener type="#{'anyid'}" binding="#{mybean}"/>
+ * 
+ * The value of mybean could be already on the context, so this
+ * converter avoid creating a new variable and use the previous one.
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class DelegateActionListener implements ActionListener, StateHolder
+{
+
+    private ValueExpression _type;
+    private ValueExpression _binding;
+
+    public DelegateActionListener()
+    {
+    }
+
+    public DelegateActionListener(ValueExpression type, ValueExpression binding)
+    {
+        super();
+        _type = type;
+        _binding = binding;
+    }
+
+    public boolean isTransient()
+    {
+        return false;
+    }
+
+    public void restoreState(FacesContext facesContext, Object state)
+    {
+        Object[] values = (Object[]) state;
+        _type = (ValueExpression) values[0];
+        _binding = (ValueExpression) values[1];
+    }
+
+    public Object saveState(FacesContext facesContext)
+    {
+        Object[] values = new Object[2];
+        values[0] = _type;
+        values[1] = _binding;
+        return values;
+    }
+
+    public void setTransient(boolean arg0)
+    {
+        // Do nothing        
+    }
+
+    private ActionListener _getDelegate()
+    {
+        return _createActionListener();
+    }
+
+    private ActionListener _createActionListener()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ActionListener listener = null;
+        // type and/or binding must be specified
+        try
+        {
+            if (null != _binding)
+            {
+                try
+                {
+                    listener = (ActionListener) _binding.getValue(facesContext
+                            .getELContext());
+                    if (null != listener)
+                    {
+                        return listener;
+                    }
+                }
+                catch (ELException e)
+                {
+                    //throw new JspException("Exception while evaluating the binding attribute
of Component "
+                    //        + component.getId(), e);
+                }
+            }
+            if (null != _type)
+            {
+                String className;
+                if (_type.isLiteralText())
+                {
+                    className = _type.getExpressionString();
+                }
+                else
+                {
+                    className = (String) _type.getValue(facesContext
+                            .getELContext());
+                }
+                listener = null;
+                //listener = (ActionListener) ClassUtils.newInstance(className);
+                if (null != _binding)
+                {
+                    try
+                    {
+                        _binding
+                                .setValue(facesContext.getELContext(), listener);
+                    }
+                    catch (ELException e)
+                    {
+                        //throw new JspException("Exception while evaluating the binding
attribute of Component "
+                        //        + component.getId(), e);
+                    }
+                }
+                return listener;
+            }
+        }
+        catch (ClassCastException e)
+        {
+            throw new FacesException(e);
+        }
+        return listener;
+    }
+
+    public void processAction(ActionEvent event)
+            throws AbortProcessingException
+    {
+        _getDelegate().processAction(event);
+    }
+
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateActionListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.taglib.core;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+/**
+ * This class is used in conjunction with ConverterImplTag. 
+ * 
+ * When a tag like this is in a jsp page:
+ * 
+ * <f:converter binding="#{mybean}"/>
+ *  
+ *  or
+ *  
+ * <f:converter converterId="#{'anyid'}" binding="#{mybean}"/>
+ * 
+ * The value of mybean could be already on the context, so this
+ * converter avoid creating a new variable and use the previous one.
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$ 
+ */
+public class DelegateConverter implements Converter, StateHolder
+{
+
+    private ValueExpression _converterId;
+    private ValueExpression _binding;
+    private String _converterIdString = null;
+    
+    public DelegateConverter(){
+        
+    }
+    
+    public DelegateConverter(ValueExpression id, ValueExpression binding, String converterIdString)
+    {
+        super();
+        _converterId = id;
+        _binding = binding;
+        _converterIdString = converterIdString;
+    }
+
+    public boolean isTransient()
+    {
+        return false;
+    }
+
+    public void restoreState(FacesContext facesContext, Object state)
+    {
+        Object[] values = (Object[]) state;
+        _converterId = (ValueExpression) values[0];
+        _binding = (ValueExpression) values[1];
+        _converterIdString = (String) values[2];
+    }
+
+    public Object saveState(FacesContext facesContext)
+    {
+        Object[] values = new Object[3];
+        values[0] = _converterId;
+        values[1] = _binding;
+        values[2] = _converterIdString;
+        return values;
+    }
+
+    public void setTransient(boolean arg0)
+    {
+        // Do nothing        
+    }
+
+    public Object getAsObject(FacesContext facesContext, UIComponent component,
+            String value)
+    {
+        return _getDelegate().getAsObject(facesContext, component, value);
+    }
+
+    public String getAsString(FacesContext facesContext, UIComponent component,
+            Object value)
+    {
+        return _getDelegate().getAsString(facesContext, component, value);
+    }
+
+    private Converter _getDelegate()
+    {
+        return _createConverter();
+    }
+
+    private Converter _createConverter()
+    {
+        Converter converter = null;
+
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ELContext elContext = facesContext.getELContext();
+
+        // try to create the converter from the binding expression first, and then from
+        // the converterId
+        if (_binding != null)
+        {
+            try
+            {
+                converter = (Converter) _binding.getValue(elContext);
+
+                if (converter != null)
+                {
+                    return converter;
+                }
+            }
+            catch (Exception e)
+            {
+                throw new ConverterException("Exception creating converter using binding",
e);
+            }
+        }
+
+        if ((_converterId != null) || (_converterIdString != null))
+        {
+            try
+            {
+                if (null != _converterIdString)
+                {
+                    converter = facesContext.getApplication().createConverter(_converterIdString);
+                } else 
+                {
+                    String converterId = (String) _converterId.getValue(elContext);
+                    converter = facesContext.getApplication().createConverter(converterId);
+                }
+
+                // with binding no converter was created, set its value with the converter
+                // created using the converterId
+                if (converter != null && _binding != null)
+                {
+                    _binding.setValue(elContext, converter);
+                }
+            }
+            catch (Exception e)
+            {
+                throw new ConverterException("Exception creating converter with converterId:
" + _converterId, e);
+            }
+        }
+
+        return converter;
+    }
+
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,155 @@
+/*
+ * 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.taglib.core;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.servlet.jsp.JspException;
+
+/**
+ * This class is used in conjunction with ValidatorImplTag. 
+ * 
+ * When a tag like this is in a jsp page:
+ * 
+ * <f:validator binding="#{mybean}"/>
+ *  
+ *  or
+ *  
+ * <f:validator validatorId="#{'anyid'}" binding="#{mybean}"/>
+ * 
+ * The value of mybean could be already on the context, so this
+ * converter avoid creating a new variable and use the previous one.
+ *
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ *
+ */
+public class DelegateValidator implements Validator, StateHolder
+{
+
+    private ValueExpression _validatorId;
+    private ValueExpression _binding;
+    private String _validatorIdString = null;
+    
+    public DelegateValidator(){
+        
+    }
+    
+    public DelegateValidator(ValueExpression id, ValueExpression binding, String converterIdString)
+    {
+        super();
+        _validatorId = id;
+        _binding = binding;
+        _validatorIdString = converterIdString;
+    }
+
+    public boolean isTransient()
+    {
+        return false;
+    }
+
+    public void restoreState(FacesContext facesContext, Object state)
+    {
+        Object[] values = (Object[]) state;
+        _validatorId = (ValueExpression) values[0];
+        _binding = (ValueExpression) values[1];
+        _validatorIdString = (String) values[2];
+    }
+
+    public Object saveState(FacesContext facesContext)
+    {
+        Object[] values = new Object[3];
+        values[0] = _validatorId;
+        values[1] = _binding;
+        values[2] = _validatorIdString;
+        return values;
+    }
+
+    public void setTransient(boolean arg0)
+    {
+        // Do nothing        
+    }
+
+    private Validator _getDelegate()
+    {
+        return _createValidator();
+    }
+
+    private Validator _createValidator()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ELContext elContext = facesContext.getELContext();
+        if (null != _binding)
+        {
+            Object validator;
+            try
+            {
+                validator = _binding.getValue(elContext);
+            } catch (Exception e)
+            {
+                throw new ValidatorException(new FacesMessage("Error while creating the Validator"),
e);
+            }
+            if (validator instanceof Validator)
+            {
+                return (Validator) validator;
+            }
+        }
+        Application application = facesContext.getApplication();
+        Validator validator = null;
+        try
+        {
+            // first check if an ValidatorId was set by a method
+            if (null != _validatorIdString)
+            {
+                validator = application.createValidator(_validatorIdString);
+            } else if (null != _validatorId)
+            {
+                String validatorId = (String) _validatorId.getValue(elContext);
+                validator = application.createValidator(validatorId);
+            }
+        } catch (Exception e)
+        {
+            throw new ValidatorException(new FacesMessage("Error while creating the Validator"),
e);
+        }
+
+        if (null != validator)
+        {
+            if (null != _binding)
+            {
+                _binding.setValue(elContext, validator);
+            }
+            return validator;
+        }
+        throw new ValidatorException(new FacesMessage("validatorId and/or binding must be
specified"));
+    }
+
+    public void validate(FacesContext facesContext, UIComponent component, Object value)
+            throws ValidatorException
+    {
+        _getDelegate().validate(facesContext, component, value);
+    }
+
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.taglib.core;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.StateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.event.ValueChangeListener;
+
+
+/**
+ * This class is used in conjunction with ValueChangeListenerTag. 
+ * 
+ * When a tag like this is in a jsp page:
+ * 
+ * <f:valueChangeListener binding="#{mybean}"/>
+ *  
+ *  or
+ *  
+ * <f:valueChangeListener type="#{'anyid'}" binding="#{mybean}"/>
+ * 
+ * The value of mybean could be already on the context, so this
+ * converter avoid creating a new variable and use the previous one.
+ * 
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class DelegateValueChangeListener implements ValueChangeListener, StateHolder
+{
+
+    private ValueExpression _type;
+    private ValueExpression _binding;
+
+    public DelegateValueChangeListener()
+    {
+    }
+
+    public DelegateValueChangeListener(ValueExpression type, ValueExpression binding)
+    {
+        super();
+        _type = type;
+        _binding = binding;
+    }
+
+    public boolean isTransient()
+    {
+        return false;
+    }
+
+    public void restoreState(FacesContext facesContext, Object state)
+    {
+        Object[] values = (Object[]) state;
+        _type = (ValueExpression) values[0];
+        _binding = (ValueExpression) values[1];
+    }
+
+    public Object saveState(FacesContext facesContext)
+    {
+        Object[] values = new Object[2];
+        values[0] = _type;
+        values[1] = _binding;
+        return values;
+    }
+
+    public void setTransient(boolean arg0)
+    {
+        // Do nothing        
+    }
+
+    private ValueChangeListener _getDelegate()
+    {
+        return _createValueChangeListener();
+    }
+
+    private ValueChangeListener _createValueChangeListener()
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ValueChangeListener listener = null;
+        // type and/or binding must be specified
+        try
+        {
+            if (null != _binding)
+            {
+                try
+                {
+                    listener = (ValueChangeListener) _binding.getValue(facesContext
+                            .getELContext());
+                    if (null != listener)
+                    {
+                        return listener;
+                    }
+                }
+                catch (ELException e)
+                {
+                    //throw new JspException("Exception while evaluating the binding attribute
of Component "
+                    //        + component.getId(), e);
+                }
+            }
+            if (null != _type)
+            {
+                String className;
+                if (_type.isLiteralText())
+                {
+                    className = _type.getExpressionString();
+                }
+                else
+                {
+                    className = (String) _type.getValue(facesContext
+                            .getELContext());
+                }
+                listener = null;
+                //listener = (ActionListener) ClassUtils.newInstance(className);
+                if (null != _binding)
+                {
+                    try
+                    {
+                        _binding
+                                .setValue(facesContext.getELContext(), listener);
+                    }
+                    catch (ELException e)
+                    {
+                        //throw new JspException("Exception while evaluating the binding
attribute of Component "
+                        //        + component.getId(), e);
+                    }
+                }
+                return listener;
+            }
+        }
+        catch (ClassCastException e)
+        {
+            throw new FacesException(e);
+        }
+        return listener;
+    }
+
+    public void processValueChange(ValueChangeEvent event)
+            throws AbortProcessingException
+    {
+        _getDelegate().processValueChange(event);
+    }
+
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/DelegateValueChangeListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/GenericListenerTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/GenericListenerTag.java?rev=600199&r1=600198&r2=600199&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/GenericListenerTag.java
(original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/GenericListenerTag.java
Sat Dec  1 13:28:15 2007
@@ -21,6 +21,7 @@
 import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.event.ActionListener;
 import javax.faces.webapp.UIComponentClassicTagBase;
 import javax.faces.webapp.UIComponentELTag;
 import javax.servlet.jsp.JspException;
@@ -64,6 +65,8 @@
 
     protected abstract void addListener(_Holder holder, _Listener listener);
 
+    protected abstract _Listener createDelegateListener(ValueExpression type, ValueExpression
binding);
+    
     public int doStartTag() throws JspException
     {
         UIComponentClassicTagBase componentTag = UIComponentELTag.getParentUIComponentClassicTagBase(pageContext);
@@ -97,7 +100,20 @@
             throw new JspException(
                     "Component " + ((UIComponent) holder).getId() + " is not instance of
" + _holderClazz.getName());
         }
-
+        
+        if (_type != null && _type.isLiteralText())
+        {
+            createListener(holder,component);
+        }else{
+            addListener(holder, createDelegateListener(_type,_binding));
+        }
+        
+        return Tag.SKIP_BODY;
+    }
+    
+    protected void createListener(_Holder holder, UIComponent component) 
+        throws JspException
+    {
         FacesContext facesContext = FacesContext.getCurrentInstance();
         _Listener listener;
         // type and/or binding must be specified
@@ -112,7 +128,7 @@
                     {
                         addListener(holder, listener);
                         // no need for further processing
-                        return Tag.SKIP_BODY;
+                        return;
                     }
                 }
                 catch (ELException e)
@@ -131,7 +147,9 @@
                 {
                     className = (String) _type.getValue(facesContext.getELContext());
                 }
-                listener = (_Listener) ClassUtils.newInstance(className);
+                
+                listener = null;
+                //listener = (ActionListener) ClassUtils.newInstance(className);
                 if (null != _binding)
                 {
                     try
@@ -148,8 +166,7 @@
         } catch (ClassCastException e)
         {
             throw new JspException(e);
-        }
-
-        return Tag.SKIP_BODY;
+        }        
     }
+    
 }

Added: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java?rev=600199&view=auto
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
(added)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
Sat Dec  1 13:28:15 2007
@@ -0,0 +1,131 @@
+/*
+* Copyright 2004-2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.myfaces.taglib.core;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorELTag;
+import javax.servlet.jsp.JspException;
+
+/**
+ * Basic Validator implementation.
+ *
+ * @author Leonardo Uribe (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ValidatorImplTag
+        extends ValidatorELTag
+{
+    private ValueExpression _validatorId;
+    private ValueExpression _binding;
+    private String _validatorIdString = null;
+
+    public void setValidatorId(ValueExpression validatorId)
+    {
+        _validatorId = validatorId;
+    }
+
+    public void setBinding(ValueExpression binding)
+    {
+        _binding = binding;
+    }
+
+    /**
+     * Use this method to specify the validatorId programmatically.
+     *
+     * @param validatorIdString
+     */
+    public void setValidatorIdString(String validatorIdString)
+    {
+        _validatorIdString = validatorIdString;
+    }
+
+    public void release()
+    {
+        super.release();
+        _validatorId = null;
+        _binding = null;
+        _validatorIdString = null;
+    }
+    
+    protected Validator createValidator() throws javax.servlet.jsp.JspException
+    {
+        Thread.dumpStack();
+        if (_validatorIdString != null)
+        {
+            return this.createClassicValidator();
+        }        
+        if (_validatorId != null && _validatorId.isLiteralText())
+        {
+            return this.createClassicValidator();
+        }        
+        
+        return new DelegateValidator(_validatorId, _binding,
+                _validatorIdString);
+    }    
+
+    protected Validator createClassicValidator() throws javax.servlet.jsp.JspException
+    {
+        FacesContext facesContext = FacesContext.getCurrentInstance();
+        ELContext elContext = facesContext.getELContext();
+        if (null != _binding)
+        {
+            Object validator;
+            try
+            {
+                validator = _binding.getValue(elContext);
+            } catch (Exception e)
+            {
+                throw new JspException("Error while creating the Validator", e);
+            }
+            if (validator instanceof Validator)
+            {
+                return (Validator) validator;
+            }
+        }
+        Application application = facesContext.getApplication();
+        Validator validator = null;
+        try
+        {
+            // first check if an ValidatorId was set by a method
+            if (null != _validatorIdString)
+            {
+                validator = application.createValidator(_validatorIdString);
+            } else if (null != _validatorId)
+            {
+                String validatorId = (String) _validatorId.getValue(elContext);
+                validator = application.createValidator(validatorId);
+            }
+        } catch (Exception e)
+        {
+            throw new JspException("Error while creating the Validator", e);
+        }
+
+        if (null != validator)
+        {
+            if (null != _binding)
+            {
+                _binding.setValue(elContext, validator);
+            }
+            return validator;
+        }
+        throw new JspException("validatorId and/or binding must be specified");
+    }
+
+}

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValidatorImplTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValueChangeListenerTag.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValueChangeListenerTag.java?rev=600199&r1=600198&r2=600199&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValueChangeListenerTag.java
(original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/taglib/core/ValueChangeListenerTag.java
Sat Dec  1 13:28:15 2007
@@ -15,7 +15,9 @@
  */
 package org.apache.myfaces.taglib.core;
 
+import javax.el.ValueExpression;
 import javax.faces.component.EditableValueHolder;
+import javax.faces.event.ActionListener;
 import javax.faces.event.ValueChangeListener;
 
 /**
@@ -36,4 +38,10 @@
     {
         editableValueHolder.addValueChangeListener(valueChangeListener);
     }
+    
+    protected ValueChangeListener createDelegateListener(ValueExpression type,
+            ValueExpression binding)
+    {
+        return new DelegateValueChangeListener(type,binding);
+    }    
 }

Modified: myfaces/core/trunk_1.2.x/impl/src/main/resources/META-INF/myfaces_core.tld
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/resources/META-INF/myfaces_core.tld?rev=600199&r1=600198&r2=600199&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/resources/META-INF/myfaces_core.tld (original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/resources/META-INF/myfaces_core.tld Sat Dec  1
13:28:15 2007
@@ -210,12 +210,12 @@
            associates it with the nearest parent UIComponent.
        </description>
        <name>converter</name>
-       <tag-class>org.apache.myfaces.taglib.core.ConverterTag</tag-class>
+       <tag-class>org.apache.myfaces.taglib.core.ConverterImplTag</tag-class>
        <body-content>empty</body-content>
       <attribute>
           <description>The converter's registered ID.</description>
           <name>converterId</name>
-          <required>true</required>
+          <required>false</required>
           <deferred-value>
                 <type>java.lang.String</type>
             </deferred-value>
@@ -899,7 +899,7 @@
 
         </description>
         <name>validator</name>
-       <tag-class>org.apache.myfaces.taglib.core.ValidatorTag</tag-class>
+       <tag-class>org.apache.myfaces.taglib.core.ValidatorImplTag</tag-class>
        <body-content>empty</body-content>
       <attribute>
           <description>The registered ID of the desired Validator.</description>



Mime
View raw message