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