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  package org.apache.myfaces.view.facelets.tag.jsf.core;
20  
21  import java.io.IOException;
22  import java.util.Map;
23  import javax.faces.component.UIComponent;
24  import javax.faces.view.facelets.FaceletContext;
25  import javax.faces.view.facelets.TagAttribute;
26  import javax.faces.view.facelets.TagConfig;
27  import javax.faces.view.facelets.TagException;
28  import javax.faces.view.facelets.TagHandler;
29  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
30  
31  /**
32   *
33   * @since 2.2
34   * @author Leonardo Uribe
35   */
36  @JSFFaceletTag(
37          name = "f:passThroughAttributes",
38          bodyContent = "empty")
39  public final class PassThroughAttributesHandler extends TagHandler 
40  {
41      private final TagAttribute _value;
42      
43      public PassThroughAttributesHandler(TagConfig config)
44      {
45          super(config);
46          _value = getRequiredAttribute("value");
47      }
48  
49      public void apply(FaceletContext ctx, UIComponent parent) throws IOException
50      {
51          if (parent == null)
52          {
53              throw new TagException(this.tag, "Parent UIComponent was null");
54          }
55  
56          // only process if the parent is new to the tree
57          if (parent.getParent() == null)
58          {
59              Map<String, Object> map = (Map<String, Object>) _value.getObject(ctx, Map.class);
60  
61              for (Map.Entry<String, Object> entry : map.entrySet())
62              {
63                  parent.getPassThroughAttributes().put(entry.getKey(), entry.getValue());
64              }
65          }
66      }
67  }