001    // Copyright May 4, 2006 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    package org.apache.tapestry.dojo.form;
015    
016    import org.apache.tapestry.IMarkupWriter;
017    import org.apache.tapestry.IRequestCycle;
018    import org.apache.tapestry.form.AbstractFormComponent;
019    
020    
021    /**
022     * Represents a dojo widget that manages an html form input
023     * field.
024     * 
025     * @author jkuhnert
026     * @since 4.1
027     */
028    public abstract class AbstractFormWidget extends AbstractFormComponent implements IFormWidget
029    {
030        /**
031         * {@inheritDoc}
032         */
033        public void renderWidget(IMarkupWriter writer, IRequestCycle cycle)
034        {
035            renderComponent(writer, cycle);
036        }
037        
038        /**
039         * {@inheritDoc}
040         */
041        protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
042        {
043            renderFormWidget(writer, cycle);
044        }
045        
046        /**
047         * {@inheritDoc}
048         */
049        protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
050        {
051            rewindFormWidget(writer, cycle);
052        }
053        
054        /**
055         * Called when rendering a form widget. 
056         * 
057         * @param writer
058         *          The markup writer to render with.
059         * @param cycle
060         *          The cycle associated with request.
061         */
062        protected abstract void renderFormWidget(IMarkupWriter writer, IRequestCycle cycle);
063        
064        /**
065         * Called during form submission to retrieve submitted input values. 
066         * Components should do any validation/retrieval of values in this method. 
067         * 
068         * @param writer
069         *          The passed in {@link IMarkupWriter} will be a {@link NullMarkupWriter}, making 
070         *          any content written ignored. 
071         * @param cycle
072         *           Typically used to retrieve submitted value via <code>cycle.getParameter(getName())</code>.
073         */
074        protected abstract void rewindFormWidget(IMarkupWriter writer, IRequestCycle cycle);
075    }