View Javadoc

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  
20  package org.apache.myfaces.view.facelets.tag.ui;
21  
22  import java.io.IOException;
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  import org.apache.myfaces.view.facelets.AbstractFaceletContext;
33  
34  /**
35   * NOTE: This implementation is provided for compatibility reasons and
36   * it is considered faulty. It is enabled using
37   * org.apache.myfaces.STRICT_JSF_2_FACELETS_COMPATIBILITY web config param.
38   * Don't use it if EL expression caching is enabled.
39   * 
40   * @author Jacob Hookom
41   * @version $Id: ParamHandler.java,v 1.6 2008/07/13 19:01:42 rlubke Exp $
42   */
43  //@JSFFaceletTag(name="ui:param")
44  public class LegacyParamHandler extends TagHandler
45  {
46  
47      /**
48       * The name of the variable to pass to the included Facelet.
49       */
50      //@JSFFaceletAttribute(
51      //        className="javax.el.ValueExpression",
52      //        deferredValueType="java.lang.String",
53      //        required=true)
54      private final TagAttribute name;
55  
56      /**
57       * The literal or EL expression value to assign to the named variable.
58       */
59      //@JSFFaceletAttribute(
60      //        className="javax.el.ValueExpression",
61      //        deferredValueType="java.lang.String",
62      //        required=true)
63      private final TagAttribute value;
64  
65      /**
66       * @param config
67       */
68      public LegacyParamHandler(TagConfig config)
69      {
70          super(config);
71          this.name = this.getRequiredAttribute("name");
72          this.value = this.getRequiredAttribute("value");
73      }
74  
75      /*
76       * (non-Javadoc)
77       * 
78       * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext,
79       *        javax.faces.component.UIComponent)
80       */
81      @Override
82      public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
83              ELException
84      {
85          String nameStr = getName(ctx);
86          ValueExpression valueVE = getValue(ctx);
87          //ctx.getVariableMapper().setVariable(nameStr, valueVE);
88          apply(ctx, parent, nameStr, valueVE);
89      }
90      
91      public void apply(FaceletContext ctx, UIComponent parent, String nameStr, ValueExpression valueVE)
92              throws IOException, FacesException, FaceletException, ELException
93      {    
94          ctx.getVariableMapper().setVariable(nameStr, valueVE);
95          AbstractFaceletContext actx = ((AbstractFaceletContext) ctx);
96          actx.getTemplateContext().setAllowCacheELExpressions(false);
97      }
98      
99      public String getName(FaceletContext ctx)
100     {
101         return this.name.getValue(ctx);
102     }
103     
104     public ValueExpression getValue(FaceletContext ctx)
105     {
106         return this.value.getValueExpression(ctx, Object.class);
107     }
108 }