Coverage Report - org.apache.tapestry5.internal.util.AutofocusValidationDecorator
 
Classes in this File Line Coverage Branch Coverage Complexity
AutofocusValidationDecorator
100%
11/11
100%
6/6
0
 
 1  
 //  Copyright 2008 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.internal.util;
 16  
 
 17  
 import org.apache.tapestry5.*;
 18  
 
 19  
 /**
 20  
  * Used by {@link org.apache.tapestry5.corelib.components.Form} to determine which fields will be focused and a what
 21  
  * priority.
 22  
  */
 23  
 public class AutofocusValidationDecorator extends ValidationDecoratorWrapper
 24  
 {
 25  
     private final ValidationTracker tracker;
 26  
 
 27  
     private final RenderSupport renderSupport;
 28  
 
 29  
     public AutofocusValidationDecorator(ValidationDecorator delegate, ValidationTracker tracker,
 30  
                                         RenderSupport renderSupport)
 31  
     {
 32  364
         super(delegate);
 33  364
         this.tracker = tracker;
 34  364
         this.renderSupport = renderSupport;
 35  364
     }
 36  
 
 37  
     @Override
 38  
     public void insideField(Field field)
 39  
     {
 40  692
         super.insideField(field);
 41  
 
 42  692
         if (!field.isDisabled())
 43  
         {
 44  680
             renderSupport.autofocus(getPriority(field), field.getClientId());
 45  
         }
 46  692
     }
 47  
 
 48  
     private FieldFocusPriority getPriority(Field field)
 49  
     {
 50  680
         if (tracker.inError(field)) return FieldFocusPriority.IN_ERROR;
 51  
 
 52  634
         if (field.isRequired()) return FieldFocusPriority.REQUIRED;
 53  
 
 54  174
         return FieldFocusPriority.OPTIONAL;
 55  
     }
 56  
 }