001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005//     http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.corelib.mixins;
014
015import org.apache.tapestry5.BindingConstants;
016import org.apache.tapestry5.Field;
017import org.apache.tapestry5.FieldFocusPriority;
018import org.apache.tapestry5.annotations.AfterRender;
019import org.apache.tapestry5.annotations.Environmental;
020import org.apache.tapestry5.annotations.InjectContainer;
021import org.apache.tapestry5.annotations.Parameter;
022import org.apache.tapestry5.corelib.components.Form;
023import org.apache.tapestry5.ioc.annotations.Inject;
024import org.apache.tapestry5.services.javascript.JavaScriptSupport;
025import org.slf4j.Logger;
026
027/**
028 * A mixin that instruments the outer {@link org.apache.tapestry5.corelib.components.Form} on which
029 * component the focus should be activated.
030 * 
031 * This is meant to be used only with {@link org.apache.tapestry5.corelib.components.Form} component.
032 *
033 * @since 5.3
034 * @deprecated As of release 5.4, replaced by {@link org.apache.tapestry5.corelib.mixins.OverrideFieldFocus}
035 * @tapestrydoc
036 */
037@Deprecated
038public class FormFieldFocus
039{
040    @Inject
041    private Logger logger;
042
043    /**
044     * The outer Form
045     */
046    @InjectContainer
047    private Form form;
048
049    /**
050     * The {@link org.apache.tapestry5.Field} instance that will receive the focus within
051     * the {@link org.apache.tapestry5.corelib.components.Form}.
052     */
053    @Parameter(required = true, defaultPrefix = BindingConstants.COMPONENT, allowNull = false)
054    private Field focusField;
055
056    @Environmental
057    private JavaScriptSupport javascriptSupport;
058
059
060    @AfterRender
061    void focusField()
062    {
063        javascriptSupport.autofocus(FieldFocusPriority.OVERRIDE, focusField.getClientId());
064
065        logger.trace("Focus OVERRIDE done on field {}", focusField.getClientId());
066    }
067
068}