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 javax.faces.view.facelets;
20  
21  import javax.faces.view.BehaviorHolderAttachedObjectHandler;
22  
23  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
24  
25  /**
26   * @since 2.0
27   */
28  @JSFFaceletTag
29  public class BehaviorHandler extends FaceletsAttachedObjectHandler implements BehaviorHolderAttachedObjectHandler
30  {
31      private String behaviorId;
32      private TagAttribute event;
33      private TagHandlerDelegate helper;
34      
35      /**
36       * @param config
37       */
38      public BehaviorHandler(BehaviorConfig config)
39      {
40          super(config);
41          
42          behaviorId = config.getBehaviorId();
43          event = getAttribute ("event");
44      }
45      
46      public String getBehaviorId()
47      {
48          return behaviorId;
49      }
50      
51      public TagAttribute getEvent()
52      {
53          return event;
54      }
55  
56      public String getEventName ()
57      {
58          if (event == null)
59          {
60              return null;
61          }
62          
63          return event.getValue();
64      }
65      
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      protected TagHandlerDelegate getTagHandlerDelegate()
71      {
72          if (helper == null)
73          {
74              // Spec seems to indicate that the helper is created here, as opposed to other Handler
75              // instances, where it's presumably a new instance for every getter call.
76              
77              this.helper = delegateFactory.createBehaviorHandlerDelegate (this);
78          }
79          return helper;
80      }
81  }