Coverage Report - org.apache.tapestry5.corelib.base.AbstractComponentEventLink
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractComponentEventLink
100%
12/12
100%
8/8
0
 
 1  
 // Copyright 2008, 2009 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.corelib.base;
 16  
 
 17  
 import org.apache.tapestry5.BindingConstants;
 18  
 import org.apache.tapestry5.Link;
 19  
 import org.apache.tapestry5.MarkupConstants;
 20  
 import org.apache.tapestry5.MarkupWriter;
 21  
 import org.apache.tapestry5.annotations.Environmental;
 22  
 import org.apache.tapestry5.annotations.Parameter;
 23  
 import org.apache.tapestry5.ioc.annotations.Inject;
 24  
 import org.apache.tapestry5.services.ClientBehaviorSupport;
 25  
 import org.apache.tapestry5.services.Request;
 26  
 
 27  
 /**
 28  
  * Base class for link-generating components that are based on a component event request. Such events have an event
 29  
  * context and may also update a {@link org.apache.tapestry5.corelib.components.Zone}.
 30  
  */
 31  271
 public abstract class AbstractComponentEventLink extends AbstractLink
 32  
 {
 33  
     /**
 34  
      * The context for the link (optional parameter). This list of values will be converted into strings and included in
 35  
      * the URI. The strings will be coerced back to whatever their values are and made available to event handler
 36  
      * methods.
 37  
      */
 38  
     @Parameter
 39  
     private Object[] context;
 40  
 
 41  
     /**
 42  
      * Binding the zone parameter turns the link into a an Ajax control that causes the related zone to be updated.
 43  
      */
 44  
     @Parameter(defaultPrefix = BindingConstants.LITERAL)
 45  
     private String zone;
 46  
 
 47  
     @Environmental
 48  
     private ClientBehaviorSupport clientBehaviorSupport;
 49  
 
 50  
     @Inject
 51  
     private Request request;
 52  
 
 53  
     void beginRender(MarkupWriter writer)
 54  
     {
 55  2356
         if (isDisabled()) return;
 56  
 
 57  2320
         Link link = createLink(context);
 58  
 
 59  2320
         writeLink(writer, link);
 60  
 
 61  2320
         if (zone != null)
 62  
         {
 63  170
             if (!request.isXHR())
 64  106
                 writer.getElement().forceAttributes(MarkupConstants.ONCLICK, MarkupConstants.WAIT_FOR_PAGE);
 65  
 
 66  170
             clientBehaviorSupport.linkZone(getClientId(), zone, link);
 67  
         }
 68  2320
     }
 69  
 
 70  
     /**
 71  
      * Invoked to create the Link that will become the href attribute of the output.
 72  
      *
 73  
      * @param eventContext the context as an object array, possibly null
 74  
      */
 75  
     protected abstract Link createLink(Object[] eventContext);
 76  
 
 77  
     void afterRender(MarkupWriter writer)
 78  
     {
 79  2356
         if (isDisabled()) return;
 80  
 
 81  2320
         writer.end(); // <a>
 82  2320
     }
 83  
 }