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 jakarta.faces.component;
20  
21  import jakarta.el.ValueExpression;
22  import jakarta.faces.el.ValueBinding;
23  
24  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
25  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
26  
27  /**
28   * Displays a graphical image.
29   * <p>
30   * See the javadoc for this class in the
31   * <a href="http://java.sun.com/j2ee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
32   * for further details.
33   */
34  @JSFComponent(defaultRendererType = "jakarta.faces.Image")
35  public class UIGraphic extends UIComponentBase
36  {
37      public static final String COMPONENT_TYPE = "jakarta.faces.Graphic";
38      public static final String COMPONENT_FAMILY = "jakarta.faces.Graphic";
39  
40      private static final String URL_PROPERTY = "url";
41      private static final String VALUE_PROPERTY = "value";
42  
43      /**
44       * Construct an instance of the UIGraphic.
45       */
46      public UIGraphic()
47      {
48          setRendererType("jakarta.faces.Image");
49      }
50  
51      @Override
52      public String getFamily()
53      {
54          return COMPONENT_FAMILY;
55      }
56  
57      /**
58       * An alias for the "value" attribute.
59       */
60      @JSFProperty
61      public String getUrl()
62      {
63          return (String) getValue();
64      }
65  
66      public void setUrl(String url)
67      {
68          setValue(url);
69      }
70  
71      /**
72       * @deprecated Use getValueExpression instead
73       */
74      @Override
75      public ValueBinding getValueBinding(String name)
76      {
77          if (URL_PROPERTY.equals(name)) 
78          {
79              return super.getValueBinding(VALUE_PROPERTY);
80          } 
81          else 
82          {
83              return super.getValueBinding(name);
84          }
85      }
86  
87      /**
88       * @deprecated Use setValueExpression instead
89       */
90      @Override
91      public void setValueBinding(String name, ValueBinding binding) 
92      {
93          if (URL_PROPERTY.equals(name)) 
94          {
95              super.setValueBinding(VALUE_PROPERTY, binding);
96          } 
97          else 
98          {
99              super.setValueBinding(name, binding);
100         }
101     }
102 
103     @Override
104     public ValueExpression getValueExpression(String name)
105     {
106         if (URL_PROPERTY.equals(name))
107         {
108             return super.getValueExpression(VALUE_PROPERTY);
109         }
110         else
111         {
112             return super.getValueExpression(name);
113         }
114     }
115 
116     @Override
117     public void setValueExpression(String name, ValueExpression binding)
118     {
119         if (URL_PROPERTY.equals(name))
120         {
121             super.setValueExpression(VALUE_PROPERTY, binding);
122         }
123         else
124         {
125             super.setValueExpression(name, binding);
126         }
127     }
128 
129     /**
130      * The URL of the image.
131      * <p>
132      * If the URL starts with a '/', it is relative to the context path of the web application.
133      * </p>
134      */
135     @JSFProperty
136     public Object getValue()
137     {
138         return  getStateHelper().eval(PropertyKeys.value);
139     }
140 
141     public void setValue(Object value)
142     {
143         getStateHelper().put(PropertyKeys.value, value );
144     }
145     
146     enum PropertyKeys
147     {
148          value
149     }
150 }