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