Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]

    1   /*
    2    * $Id: UIGraphic.java,v 1.43 2007/04/27 22:00:04 ofung Exp $
    3    */
    4   
    5   /*
    6    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    7    * 
    8    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   package javax.faces.component;
   42   
   43   
   44   import javax.el.ValueExpression;
   45   import javax.faces.context.FacesContext;
   46   import javax.faces.el.ValueBinding;
   47   
   48   
   49   /**
   50    * <p><strong>UIGraphic</strong> is a {@link UIComponent} that displays
   51    * a graphical image to the user.  The user cannot manipulate this component;
   52    * it is for display purposes only.</p>
   53    *
   54    * <p>By default, the <code>rendererType</code> property must be set to
   55    * "<code>javax.faces.Image</code>".  This value can be changed by calling the
   56    * <code>setRendererType()</code> method.</p>
   57    */
   58   
   59   public class UIGraphic extends UIComponentBase {
   60   
   61       /**
   62        * Properties that are tracked by state saving.
   63        */
   64       enum PropertyKeys {
   65   
   66           /**
   67            * <p>The local value of this {@link UIComponent}.</p>
   68            */
   69           value
   70       }
   71   
   72       // ------------------------------------------------------ Manifest Constants
   73   
   74   
   75       /**
   76        * <p>The standard component type for this component.</p>
   77        */
   78       public static final String COMPONENT_TYPE = "javax.faces.Graphic";
   79   
   80   
   81       /**
   82        * <p>The standard component family for this component.</p>
   83        */
   84       public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
   85   
   86   
   87       // ------------------------------------------------------------ Constructors
   88   
   89   
   90       /**
   91        * <p>Create a new {@link UIGraphic} instance with default property
   92        * values.</p>
   93        */
   94       public UIGraphic() {
   95   
   96           super();
   97           setRendererType("javax.faces.Image");
   98   
   99       }
  100   
  101   
  102       // ------------------------------------------------------ Instance Variables
  103   
  104   
  105       //private Object value = null;
  106   
  107   
  108       // -------------------------------------------------------------- Properties
  109   
  110   
  111       public String getFamily() {
  112   
  113           return (COMPONENT_FAMILY);
  114   
  115       }
  116   
  117   
  118       /**
  119        * <p>Return the image URL for this {@link UIGraphic}.  This method is a
  120        * typesafe alias for <code>getValue()</code>.</p>
  121        */
  122       public String getUrl() {
  123   
  124           return ((String) getValue());
  125   
  126       }
  127   
  128   
  129       /**
  130        * <p>Set the image URL for this {@link UIGraphic}.  This method is a
  131        * typesafe alias for <code>setValue()</code>.</p>
  132        *
  133        * @param url The new image URL
  134        */
  135       public void setUrl(String url) {
  136   
  137           setValue(url);
  138   
  139       }
  140   
  141   
  142   
  143   
  144       /**
  145        * <p>Returns the <code>value</code> property of the
  146        * <code>UIGraphic</code>. This will typically be rendered as an URL.</p>
  147        */
  148       public Object getValue() {
  149   
  150           return getStateHelper().eval(PropertyKeys.value);
  151   
  152       }
  153   
  154   
  155       /**
  156        * <p>Sets the <code>value</code> property of the <code>UIGraphic</code>.
  157        * This will typically be rendered as an URL.</p>
  158        * 
  159        * @param value the new value
  160        */
  161       public void setValue(Object value) {
  162   
  163           getStateHelper().put(PropertyKeys.value, value);
  164   
  165       }
  166   
  167   
  168       // ---------------------------------------------------------------- Bindings
  169   
  170   
  171       /**
  172        * <p>Return any {@link ValueBinding} set for <code>value</code> if a
  173        * {@link ValueBinding} for <code>url</code> is requested; otherwise,
  174        * perform the default superclass processing for this method.</p>
  175        *
  176        * @param name Name of the attribute or property for which to retrieve
  177        *  a {@link ValueBinding}
  178        *
  179        * @throws NullPointerException if <code>name</code>
  180        *  is <code>null</code>
  181        *
  182        * @deprecated This has been replaced by {@link #getValueExpression(java.lang.String)}.
  183        */
  184       public ValueBinding getValueBinding(String name) {
  185   
  186           if ("url".equals(name)) {
  187               return (super.getValueBinding("value"));
  188           } else {
  189               return (super.getValueBinding(name));
  190           }
  191   
  192       }
  193   
  194   
  195       /**
  196        * <p>Store any {@link ValueBinding} specified for <code>url</code>
  197        * under <code>value</code> instead; otherwise, perform the default
  198        * superclass processing for this method.  In all cases, the
  199        * superclass is relied on to convert the <code>ValueBinding</code>
  200        * to a <code>ValueExpression</code>.</p>
  201        *
  202        * @param name Name of the attribute or property for which to set
  203        *  a {@link ValueBinding}
  204        * @param binding The {@link ValueBinding} to set, or <code>null</code>
  205        *  to remove any currently set {@link ValueBinding}
  206        *
  207        * @throws NullPointerException if <code>name</code>
  208        *  is <code>null</code>
  209        *
  210        * @deprecated This has been replaced by {@link #setValueExpression}.
  211        */
  212       public void setValueBinding(String name, ValueBinding binding) {
  213   
  214           if ("url".equals(name)) {
  215               super.setValueBinding("value", binding);
  216           } else {
  217               super.setValueBinding(name, binding);
  218           }
  219   
  220       }
  221   
  222       /**
  223        * <p>Return any {@link ValueExpression} set for <code>value</code> if a
  224        * {@link ValueExpression} for <code>url</code> is requested; otherwise,
  225        * perform the default superclass processing for this method.</p>
  226        *
  227        * @param name Name of the attribute or property for which to retrieve
  228        *  a {@link ValueExpression}
  229        *
  230        * @throws NullPointerException if <code>name</code>
  231        *  is <code>null</code>
  232        * @since 1.2
  233        */
  234       public ValueExpression getValueExpression(String name) {
  235   
  236           if ("url".equals(name)) {
  237               return (super.getValueExpression("value"));
  238           } else {
  239               return (super.getValueExpression(name));
  240           }
  241   
  242       }
  243       
  244       /**
  245        * <p>Store any {@link ValueExpression} specified for <code>url</code> under
  246        * <code>value</code> instead; otherwise, perform the default superclass
  247        * processing for this method.</p>
  248        *
  249        * @param name Name of the attribute or property for which to set
  250        *  a {@link ValueExpression}
  251        * @param binding The {@link ValueExpression} to set, or <code>null</code>
  252        *  to remove any currently set {@link ValueExpression}
  253        *
  254        * @throws NullPointerException if <code>name</code>
  255        *  is <code>null</code>
  256        * @since 1.2
  257        */
  258       public void setValueExpression(String name, ValueExpression binding) {
  259   
  260           if ("url".equals(name)) {
  261               super.setValueExpression("value", binding);
  262           } else {
  263               super.setValueExpression(name, binding);
  264           }
  265   
  266       }
  267   
  268       // ----------------------------------------------------- StateHolder Methods
  269   
  270   
  271   
  272   
  273   }

Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]