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.Field;
016import org.apache.tapestry5.FieldFocusPriority;
017import org.apache.tapestry5.annotations.AfterRender;
018import org.apache.tapestry5.annotations.Environmental;
019import org.apache.tapestry5.annotations.InjectContainer;
020import org.apache.tapestry5.ioc.annotations.Inject;
021import org.apache.tapestry5.services.javascript.JavaScriptSupport;
022import org.slf4j.Logger;
023
024/**
025 * A mixin that let a {@link org.apache.tapestry5.Field} gain focus.
026 *
027 * This supersede {@link org.apache.tapestry5.corelib.mixins.FormFieldFocus} in 5.4
028 *
029 * @since 5.4
030 * @tapestrydoc
031 */
032public class OverrideFieldFocus
033{
034    @Inject
035    private Logger logger;
036
037    /**
038     * The outer Form
039     */
040    @InjectContainer
041    private Field container;
042
043    @Environmental
044    private JavaScriptSupport javascriptSupport;
045
046
047    @AfterRender
048    void focusField()
049    {
050        javascriptSupport.autofocus(FieldFocusPriority.OVERRIDE, container.getClientId());
051
052        logger.trace("Focus OVERRIDE done on field {}", container.getClientId());
053    }
054
055}