View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.behavior.javascript;
23  
24  import javax.faces.application.ResourceDependency;
25  
26  import org.primefaces.behavior.base.AbstractBehavior;
27  import org.primefaces.behavior.base.BehaviorAttribute;
28  
29  /**
30   * Client Behavior class for the <code>Javascript</code> behavior.
31   *
32   * @author Thomas Andraschko / last modified by $Author$
33   * @version $Revision$
34   * @since 0.2
35   */
36  @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
37  @ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js")
38  @ResourceDependency(library = "primefaces", name = "core.js")
39  @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js")
40  public class JavascriptBehavior extends AbstractBehavior {
41  
42      public static final String BEHAVIOR_ID = "org.primefaces.extensions.behavior.JavascriptBehavior";
43      private static final String DEFAULT_RENDERER = "org.primefaces.extensions.behavior.JavascriptBehaviorRenderer";
44  
45      @SuppressWarnings("java:S115")
46      public enum PropertyKeys implements BehaviorAttribute {
47  
48          disabled(Boolean.class), execute(String.class);
49  
50          private final Class<?> expectedType;
51  
52          PropertyKeys(Class<?> expectedType) {
53              this.expectedType = expectedType;
54          }
55  
56          @Override
57          public Class<?> getExpectedType() {
58              return expectedType;
59          }
60  
61      }
62  
63      @Override
64      public String getRendererType() {
65          return DEFAULT_RENDERER;
66      }
67  
68      @Override
69      protected BehaviorAttribute[] getAllAttributes() {
70          return PropertyKeys.values();
71      }
72  
73      public final String getExecute() {
74          return eval(PropertyKeys.execute, null);
75      }
76  
77      public void setExecute(final String execute) {
78          setLiteral(PropertyKeys.execute, execute);
79      }
80  
81      public boolean isDisabled() {
82          return eval(PropertyKeys.disabled, Boolean.FALSE);
83      }
84  
85      public void setDisabled(boolean disabled) {
86          setLiteral(PropertyKeys.disabled, disabled);
87      }
88  
89  }