Coverage Report - org.apache.myfaces.taglib.core.SetPropertyActionListenerTag
 
Classes in this File Line Coverage Branch Coverage Complexity
SetPropertyActionListenerTag
0%
0/27
0%
0/12
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.taglib.core;
 20  
 
 21  
 import javax.el.ValueExpression;
 22  
 import javax.faces.component.ActionSource;
 23  
 import javax.faces.component.UIComponent;
 24  
 import javax.faces.event.ActionListener;
 25  
 import javax.faces.webapp.UIComponentClassicTagBase;
 26  
 import javax.servlet.jsp.JspException;
 27  
 import javax.servlet.jsp.tagext.TagSupport;
 28  
 
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 
 32  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspAttribute;
 33  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag;
 34  
 import org.apache.myfaces.event.SetPropertyActionListener;
 35  
 
 36  
 /**
 37  
  * @author Dennis Byrne
 38  
  * @since 1.2
 39  
  */
 40  
 @JSFJspTag(
 41  
         name="f:setPropertyActionListener",
 42  
         bodyContent="empty")
 43  0
 public class SetPropertyActionListenerTag extends TagSupport
 44  
 {
 45  
     
 46  0
     private static final Log log = LogFactory.getLog(SetPropertyActionListenerTag.class);
 47  
     
 48  
     private ValueExpression target;
 49  
     
 50  
     private ValueExpression value;
 51  
 
 52  
     public int doStartTag() throws JspException 
 53  
     {
 54  
         
 55  0
         if(log.isDebugEnabled())
 56  0
             log.debug("JSF 1.2 Spec : Create a new instance of the ActionListener");
 57  
 
 58  0
         ActionListener actionListener = new SetPropertyActionListener(target, value);
 59  
         
 60  0
         UIComponentClassicTagBase tag = UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
 61  
         
 62  0
         if(tag == null)
 63  0
             throw new JspException("Could not find a " +
 64  
                     "parent UIComponentClassicTagBase ... is this " +
 65  
                     "tag in a child of a UIComponentClassicTagBase?");
 66  
         
 67  0
         if(tag.getCreated())
 68  
         {
 69  
             
 70  0
             UIComponent component = tag.getComponentInstance();
 71  
             
 72  0
             if(component == null)
 73  0
                 throw new JspException(" Could not locate a UIComponent " +
 74  
                         "for a UIComponentClassicTagBase w/ a " +
 75  
                         "JSP id of " + tag.getJspId());
 76  
             
 77  0
             if( ! ( component instanceof ActionSource ) )
 78  0
                 throw new JspException("Component w/ id of " + component.getId() 
 79  
                         + " is associated w/ a tag w/ JSP id of " + tag.getJspId() 
 80  
                         + ". This component is of type " + component.getClass() 
 81  
                         + ", which is not an " + ActionSource.class );
 82  
             
 83  0
             if(log.isDebugEnabled())
 84  0
                 log.debug(" ... register it with the UIComponent " +
 85  
                         "instance associated with our most immediately " +
 86  
                         "surrounding UIComponentTagBase");
 87  
             
 88  0
             ((ActionSource)component).addActionListener(actionListener);
 89  
             
 90  
         }
 91  
         
 92  0
         return SKIP_BODY;
 93  
     }
 94  
     
 95  
     /**
 96  
      * ValueExpression for the destination of the value attribute.
 97  
      */
 98  
     @JSFJspAttribute(required=true)
 99  
     public ValueExpression getTarget()
 100  
     {
 101  0
         return target;
 102  
     }
 103  
 
 104  
     public void setTarget(ValueExpression target)
 105  
     {
 106  0
         this.target = target;
 107  0
     }
 108  
 
 109  
     /**
 110  
      * ValueExpression for the value of the target attribute.
 111  
      * 
 112  
      * @return
 113  
      */
 114  
     @JSFJspAttribute(required=true)
 115  
     public ValueExpression getValue()
 116  
     {
 117  0
         return value;
 118  
     }
 119  
 
 120  
     public void setValue(ValueExpression value)
 121  
     {
 122  0
         this.value = value;
 123  0
     }
 124  
     
 125  
     public void release() 
 126  
     {
 127  0
         target = null;
 128  0
         value = null;
 129  0
     }
 130  
     
 131  
 }