Coverage Report - org.apache.myfaces.view.facelets.tag.ui.ParamHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ParamHandler
0%
0/30
0%
0/16
2.333
 
 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.view.facelets.tag.ui;
 20  
 
 21  
 import java.io.IOException;
 22  
 
 23  
 import javax.el.ELException;
 24  
 import javax.el.ValueExpression;
 25  
 import javax.faces.FacesException;
 26  
 import javax.faces.component.UIComponent;
 27  
 import javax.faces.view.facelets.FaceletContext;
 28  
 import javax.faces.view.facelets.FaceletException;
 29  
 import javax.faces.view.facelets.TagAttribute;
 30  
 import javax.faces.view.facelets.TagConfig;
 31  
 import javax.faces.view.facelets.TagHandler;
 32  
 
 33  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletAttribute;
 34  
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 35  
 import org.apache.myfaces.util.ExternalSpecifications;
 36  
 import org.apache.myfaces.view.facelets.AbstractFaceletContext;
 37  
 import org.apache.myfaces.view.facelets.ELExpressionCacheMode;
 38  
 import org.apache.myfaces.view.facelets.el.FaceletStateValueExpression;
 39  
 import org.apache.myfaces.view.facelets.el.FaceletStateValueExpressionUEL;
 40  
 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
 41  
 import org.apache.myfaces.view.facelets.tag.jsf.FaceletState;
 42  
 
 43  
 /**
 44  
  * @author Jacob Hookom
 45  
  * @version $Id$
 46  
  */
 47  
 @JSFFaceletTag(name="ui:param")
 48  
 public class ParamHandler extends TagHandler
 49  
 {
 50  
 
 51  
     /**
 52  
      * The name of the variable to pass to the included Facelet.
 53  
      */
 54  
     @JSFFaceletAttribute(
 55  
             className="javax.el.ValueExpression",
 56  
             deferredValueType="java.lang.String",
 57  
             required=true)
 58  
     private final TagAttribute name;
 59  
 
 60  
     /**
 61  
      * The literal or EL expression value to assign to the named variable.
 62  
      */
 63  
     @JSFFaceletAttribute(
 64  
             className="javax.el.ValueExpression",
 65  
             deferredValueType="java.lang.String",
 66  
             required=true)
 67  
     private final TagAttribute value;
 68  
 
 69  
     /**
 70  
      * @param config
 71  
      */
 72  
     public ParamHandler(TagConfig config)
 73  
     {
 74  0
         super(config);
 75  0
         this.name = this.getRequiredAttribute("name");
 76  0
         this.value = this.getRequiredAttribute("value");
 77  0
     }
 78  
 
 79  
     /*
 80  
      * (non-Javadoc)
 81  
      * 
 82  
      * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext,
 83  
      *        javax.faces.component.UIComponent)
 84  
      */
 85  
     public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
 86  
             ELException
 87  
     {
 88  0
         String nameStr = getName(ctx);
 89  0
         ValueExpression valueVE = getValue(ctx);
 90  
         //ctx.getVariableMapper().setVariable(nameStr, valueVE);
 91  0
         apply(ctx, parent, nameStr, valueVE);
 92  0
     }
 93  
     
 94  
     public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE)
 95  
             throws IOException, FacesException, FaceletException, ELException
 96  
     {
 97  0
         AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
 98  0
         actx.getTemplateContext().setParameter(nameStr, valueVE);
 99  
         
 100  0
         if (actx.getTemplateContext().isAllowCacheELExpressions())
 101  
         {
 102  0
             if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) ||
 103  
                 ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode()))
 104  
             {
 105  0
                 actx.getTemplateContext().setAllowCacheELExpressions(false);
 106  
             }
 107  
         }
 108  0
     }
 109  
     
 110  
     public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE,
 111  
         String uniqueId)
 112  
             throws IOException, FacesException, FaceletException, ELException
 113  
     {
 114  0
         AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
 115  0
         if (ELExpressionCacheMode.alwaysRecompile.equals(actx.getELExpressionCacheMode()))
 116  
         {
 117  0
             FaceletState faceletState = ComponentSupport.getFaceletState(ctx, parent, true);
 118  0
             faceletState.putBinding(uniqueId, nameStr, valueVE);
 119  
             ValueExpression ve;
 120  0
             if (ExternalSpecifications.isUnifiedELAvailable())
 121  
             {
 122  0
                 ve = new FaceletStateValueExpressionUEL(uniqueId, nameStr);
 123  
             }
 124  
             else
 125  
             {
 126  0
                 ve = new FaceletStateValueExpression(uniqueId, nameStr);
 127  
             }
 128  0
             actx.getTemplateContext().setParameter(nameStr, ve);
 129  0
         }
 130  
         else
 131  
         {
 132  0
             actx.getTemplateContext().setParameter(nameStr, valueVE);
 133  
         }
 134  
         
 135  0
         if (actx.getTemplateContext().isAllowCacheELExpressions())
 136  
         {
 137  0
             if (ELExpressionCacheMode.strict.equals(actx.getELExpressionCacheMode()) ||
 138  
                 ELExpressionCacheMode.allowCset.equals(actx.getELExpressionCacheMode()))
 139  
             {
 140  0
                 actx.getTemplateContext().setAllowCacheELExpressions(false);
 141  
             }
 142  
         }
 143  0
     }
 144  
     
 145  
     public String getName(FaceletContext ctx)
 146  
     {
 147  0
         return this.name.getValue(ctx);
 148  
     }
 149  
     
 150  
     public ValueExpression getValue(FaceletContext ctx)
 151  
     {
 152  0
         return this.value.getValueExpression(ctx, Object.class);
 153  
     }
 154  
 }