001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.valid;
016    
017    import org.apache.hivemind.util.Defense;
018    import org.apache.tapestry.IRender;
019    import org.apache.tapestry.form.IFormComponent;
020    
021    import java.io.Serializable;
022    
023    /**
024     * Default implementation of {@link IFieldTracking}.
025     * 
026     * @author Howard Lewis Ship
027     * @since 1.0.8
028     */
029    
030    public class FieldTracking implements IFieldTracking, Serializable
031    {
032    
033        private static final long serialVersionUID = -5397563163968532716L;
034    
035        private transient IFormComponent _component;
036    
037        private String _input;
038    
039        private IRender _renderer;
040    
041        private String _fieldName;
042    
043        private ValidationConstraint _constraint;
044    
045        private boolean _renderErrors = true;
046    
047        /**
048         * Constructor used for unassociated errors; errors that are not about any
049         * particular field within the form.
050         */
051    
052        FieldTracking()
053        {
054        }
055    
056        /**
057         * Standard constructor for a field (with the given name), rendered by the
058         * specified component.
059         */
060    
061        FieldTracking(String fieldName, IFormComponent component)
062        {
063            Defense.notNull(fieldName, "fieldName");
064            Defense.notNull(component, "component");
065    
066            _fieldName = fieldName;
067            _component = component;
068        }
069    
070        public IFormComponent getComponent()
071        {
072            return _component;
073        }
074    
075        public IRender getErrorRenderer()
076        {
077            return _renderer;
078        }
079    
080        public void setErrorRenderer(IRender value)
081        {
082            _renderer = value;
083        }
084    
085        public String getInput()
086        {
087            return _input;
088        }
089    
090        public void setInput(String value)
091        {
092            _input = value;
093        }
094    
095        public String getFieldName()
096        {
097            return _fieldName;
098        }
099    
100        public ValidationConstraint getConstraint()
101        {
102            return _constraint;
103        }
104    
105        public void setConstraint(ValidationConstraint constraint)
106        {
107            _constraint = constraint;
108        }
109    
110        /** @since 3.0 * */
111    
112        public boolean isInError()
113        {
114            return _renderer != null;
115        }
116    
117        public boolean getRenderError()
118        {
119            return _renderErrors;
120        }
121    
122        public void setRenderError(boolean value)
123        {
124            _renderErrors = value;
125        }
126    }