/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.contrib.valid;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.valid.IValidator;
import org.apache.tapestry.valid.NumberValidator;
import org.apache.tapestry.valid.ValidField;
/**
*
* Backwards compatible version of the 1.0.7 NumericField component.
*
* <table border=1>
* <tr>
* <td>Parameter</td>
* <td>Type</td>
* <td>Read / Write </td>
* <td>Required</td>
* <td>Default</td>
* <td>Description</td>
* </tr>
*
* <tr>
* <td>value</td>
* <td>{@link Number}</td>
* <td>R / W</td>
* <td>yes</td>
* <td> </td>
* <td>The value to be updated.
*
* <p>When the form is submitted, this parameter is only updated if the value
* is valid.
*
* <p>When rendering, a null value will render as the empty string. A value
* of zero will render normally.
*
* <p>When the form is submitted, the {@link IBinding#getType() type} of the binding
* is used to determine what kind of object to convert the string to.
*
* </td>
* </tr>
*
* <tr>
* <td>minimum</td>
* <td>{@link Number}</td>
* <td>R</td>
* <td>no</td>
* <td> </td>
* <td>The minimum value accepted for the field.</td>
* </tr>
*
* <tr>
* <td>maximum</td>
* <td>{@link Number}</td>
* <td>R</td>
* <td>no</td>
* <td> </td>
* <td>The maximum value accepted for the field.</td>
* </tr>
*
* <tr>
* <td>required</td>
* <td>boolean</td>
* <td>R</td>
* <td>no</td>
* <td>false</td>
* <td>If true, then a non-null value must be provided. If the field is not
* required, and a null (all whitespace) value is supplied in the field, then the
* value parameter is <em>not</em> updated.</td>
* </tr>
*
* <tr>
* <td>displayName</td>
* <td>String</td>
* <td>R</td>
* <td>yes</td>
* <td> </td>
* <td>A textual name for the field that is used when formulating error messages.
* </td>
* </tr>
*
* </table>
*
* <p>May not contain a body. May have informal parameters.
*
* @author Howard Lewis Ship
* @version $Id: NumericField.java,v 1.1 2003/03/05 23:02:31 hlship Exp $
* @since 1.0.8
* @see ValidField
*
**/
public abstract class NumericField extends ValidField
{
private IBinding minimumBinding;
private IBinding maximumBinding;
private IBinding requiredBinding;
public IBinding getMinimumBinding()
{
return minimumBinding;
}
public void setMinimumBinding(IBinding value)
{
minimumBinding = value;
}
public IBinding getMaximumBinding()
{
return maximumBinding;
}
public void setMaximumBinding(IBinding value)
{
maximumBinding = value;
}
public IBinding getRequiredBinding()
{
return requiredBinding;
}
public void setRequiredBinding(IBinding requiredBinding)
{
this.requiredBinding = requiredBinding;
}
/**
* Overrides {@link ValidField#getValidator()} to construct
* a validator on the fly.
**/
public IValidator getValidator()
{
NumberValidator validator = new NumberValidator();
if (minimumBinding != null)
{
Number minimum = (Number) minimumBinding.getObject("minimum", Number.class);
validator.setMinimum(minimum);
}
if (maximumBinding != null)
{
Number maximum = (Number) maximumBinding.getObject("maximum", Number.class);
validator.setMaximum(maximum);
}
if (requiredBinding != null)
{
boolean required = requiredBinding.getBoolean();
validator.setRequired(required);
}
return validator;
}
}