    001    // Copyright 2007, 2008 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.tapestry5;
    016
    017    import org.apache.tapestry5.dom.Element;
    018
    019    /**
    020     * An object responsible for performing decorations around fields and field labels. The decorator is notified at
    021     * intervals by the fields and labels.
    022     * <p/>
    023     * In most western languages (written left to right) the label will render before the field, so the properties of the
    024     * Field may not be set yet (or may reflect a previous looping's rendering). It may be necessary to {@linkplain
    025     * org.apache.tapestry5.services.Heartbeat#defer(Runnable)} defer any rendering} until after the Label and the Field have
    026     * both had their change to initialize and render.
    027     */
    028    public interface ValidationDecorator
    029    {
    030        /**
    031         * Invoked by a {@link org.apache.tapestry5.corelib.components.Label} before rendering itself.
    032         *
    033         * @param field for this label
    034         */
    035        void beforeLabel(Field field);
    036
    037        /**
    038         * Invoked after the label has rendered its tag, but before it has rendered content inside the tag, to allow the
    039         * decorator to write additional attributes.
    040         *
    041         * @param field        the field corresponding to the label
    042         * @param labelElement the element for this label
    043         */
    044        void insideLabel(Field field, Element labelElement);
    045
    046
    047        /**
    048         * Invoked by {@link org.apache.tapestry5.corelib.components.Label} after rendering itself.
    049         *
    050         * @param field
    051         */
    052        void afterLabel(Field field);
    053
    054        /**
    055         * Renders immediately before the field itself. The field will typically render a single element, though a complex
    056         * field may render multiple elements or even some JavaScript.
    057         *
    058         * @param field
    059         */
    060        void beforeField(Field field);
    061
    062        /**
    063         * Invoked at a point where the decorator may write additional attributes into the field. Generally speaking, you
    064         * will want to {@linkplain ComponentResources#renderInformalParameters(MarkupWriter) render informal parameters}
    065         * <strong>before</strong> invoking this method.
    066         *
    067         * @param field
    068         */
    069        void insideField(Field field);
    070
    071        /**
    072         * Invoked after the field has completed rendering itself.
    073         */
    074        void afterField(Field field);
    075    }