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
015package org.apache.tapestry;
016
017import org.apache.tapestry.valid.IValidationDelegate;
018
019/**
020 * A generic way to access a component which defines an HTML form (or, perhaps, other similar
021 * constructs, such as a WML {@link org.apache.tapestry.wml.Go}). This interface exists so that the
022 * {@link IRequestCycle}can invoke the {@link #rewind(IMarkupWriter, IRequestCycle)}method (which
023 * is used to deal with a Form that uses the direct service). In release 1.0.5, more responsibility
024 * for forms was moved here.
025 * 
026 * @author Howard Lewis Ship
027 * @since 1.0.2
028 */
029
030public interface IForm extends IAction, FormBehavior
031{
032
033    /**
034     * Attribute name used with the request cycle; allows other components to locate the IForm.
035     * 
036     * @since 1.0.5
037     * @deprecated To be removed; use {@link TapestryUtils#FORM_ATTRIBUTE}instead.
038     */
039
040    public static final String ATTRIBUTE_NAME = TapestryUtils.FORM_ATTRIBUTE;
041
042    /**
043     * Invoked by the {@link IRequestCycle}to allow a form that uses the direct service, to respond
044     * to the form submission.
045     */
046
047    public void rewind(IMarkupWriter writer, IRequestCycle cycle);
048
049    /**
050     * Returns the name of the form. The name is determined as the form component begins to render,
051     * but is not reset (as a convienience for building client-side JavaScript event handlers). The
052     * Form (and Go) components render this name as both the name and the id attribute (so it can be
053     * used like
054     * {@link org.apache.tapestry.form.IFormComponent#getClientId() a field's clientId property}.
055     * 
056     * @since 1.0.5
057     */
058
059    public String getName();
060
061    /**
062     * Returns the validation delegate for the form. Returns null if the form does not have a
063     * delegate.
064     * 
065     * @since 1.0.8
066     */
067
068    public IValidationDelegate getDelegate();
069
070    /**
071     * Indicates whether or not client-side validation will be generated during render.
072     * 
073     * @return true, if client-side validation is enabled, false otherwise
074     * @since 4.0
075     */
076    public boolean isClientValidationEnabled();
077
078    /**
079     * Returns true if the form should support automatic field focus (that is, adding JavaScript to
080     * position the cursor into the first field of the form, automatically). This requires that the
081     * Form component be enclosed by a {@link org.apache.tapestry.html.Body} component. When a
082     * single page contains multiple Forms, only the first Form that renders will get field focus;
083     * by setting the Form's focus parameter to false, it is possible to control which Form gets
084     * focus.
085     * 
086     * @since 4.0
087     */
088
089    public boolean getFocus();
090}