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
015 package org.apache.tapestry5.corelib.mixins;
016
017 import org.apache.tapestry5.BindingConstants;
018 import org.apache.tapestry5.ClientElement;
019 import org.apache.tapestry5.Field;
020 import org.apache.tapestry5.FieldFocusPriority;
021 import org.apache.tapestry5.annotations.AfterRender;
022 import org.apache.tapestry5.annotations.Environmental;
023 import org.apache.tapestry5.annotations.InjectContainer;
024 import org.apache.tapestry5.annotations.Parameter;
025 import org.apache.tapestry5.corelib.components.Form;
026 import org.apache.tapestry5.ioc.annotations.Inject;
027 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
028 import org.slf4j.Logger;
029
030 /**
031 * A mixin that instruments the outer {@link org.apache.tapestry5.corelib.components.Form} on which
032 * component the focus should be activated.
033 * <p/>
034 * This is meant to be used only with {@link org.apache.tapestry5.corelib.components.Form} component.
035 *
036 * @since 5.3
037 * @deprecated As of release 5.4, replaced by {@link org.apache.tapestry5.corelib.mixins.OverrideFieldFocus}
038 * @tapestrydoc
039 */
040 @Deprecated
041 public class FormFieldFocus
042 {
043 @Inject
044 private Logger logger;
045
046 /**
047 * The outer Form
048 */
049 @InjectContainer
050 private Form form;
051
052 /**
053 * The {@link org.apache.tapestry5.Field} instance that will receive the focus within
054 * the {@link org.apache.tapestry5.corelib.components.Form}.
055 */
056 @Parameter(required = true, defaultPrefix = BindingConstants.COMPONENT, allowNull = false)
057 private Field focusField;
058
059 @Environmental
060 private JavaScriptSupport javascriptSupport;
061
062
063 @AfterRender
064 void focusField()
065 {
066 javascriptSupport.autofocus(FieldFocusPriority.OVERRIDE, focusField.getClientId());
067
068 logger.trace("Focus OVERRIDE done on field {}", focusField.getClientId());
069 }
070
071 }