All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jakarta.faces.component.UIImportConstants Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package jakarta.faces.component;

import jakarta.el.ValueExpression;
import jakarta.faces.view.ViewMetadata;

/**
 * 
* *

* UIImportConstants imports a mapping of all constant field values of the given type in the current * view. *

* *

* The {@link jakarta.faces.view.ViewDeclarationLanguage} implementation must cause an instance of this component to be * placed in the view for each occurrence of an <f:importConstants /> element placed inside of an * <f:metadata /> element. The user must place <f:metadata /> as a direct child of * the UIViewRoot. The {@link ViewMetadata#createMetadataView(jakarta.faces.context.FacesContext)} must * take care of actual task of importing the constants. *

* *

* Instances of this class participate in the regular Jakarta Faces lifecycle, including on Ajax requests. *

* *

* The purpose of this component is to provide a mapping of all constant field values of the given type in the current * view. Constant field values are all public static final fields of the given type. The map key represents * the constant field name as String. The map value represents the actual constant field value. This works * for classes, interfaces and enums. *

* *

Usage

* *

* The below constant fields: *

* *
 * package com.example;
 *
 * public class Foo {
 *     public static final String FOO1 = "foo1";
 *     public static final String FOO2 = "foo2";
 * }
 * 
* *
 * package com.example;
 *
 * public interface Bar {
 *     public static final String BAR1 = "bar1";
 *     public static final String BAR2 = "bar2";
 * }
 * 
* *
 * package com.example;
 *
 * public enum Baz {
 *     BAZ1, BAZ2;
 * }
 * 
* *

* Can be imported as below: *

* *
 * <f:metadata>
 *     <f:importConstants type="com.example.Foo" />
 *     <f:importConstants type="com.example.Bar" var="Barrr" />
 *     <f:importConstants type="com.example.Baz" />
 * </f:metadata>
 * 
* *

* And can be referenced as below: *

* *
 * #{Foo.FOO1}, #{Foo.FOO2}, #{Barrr.BAR1}, #{Barrr.BAR2}, #{Baz.BAZ1}, #{Baz.BAZ2}
 * 
* *
 * <h:selectOneMenu value="#{bean.baz}" >
 *     <f:selectItems value="#{Baz}" />
 * </h:selectOneMenu>
 * 
* *
* * @since 2.3 */ public class UIImportConstants extends UIComponentBase { // ---------------------------------------------------------------------------------------------- Manifest Constants /** *

* The standard component type for this component. *

*/ public static final String COMPONENT_TYPE = "jakarta.faces.ImportConstants"; /** *

* The standard component family for this component. *

*/ public static final String COMPONENT_FAMILY = "jakarta.faces.ImportConstants"; /** * Properties that are tracked by state saving. */ enum PropertyKeys { type, var; } // ---------------------------------------------------------------------------------------------------- Constructors /** *

* Create a new {@link UIImportConstants} instance with renderer type set to null. *

*/ public UIImportConstants() { setRendererType(null); } // ------------------------------------------------------------------------------------------------------ Properties @Override public String getFamily() { return COMPONENT_FAMILY; } /** *

* Returns the fully qualified name of the type to import the constant field values for. *

* * @return The fully qualified name of the type to import the constant field values for. */ public String getType() { return (String) getStateHelper().eval(PropertyKeys.type); } /** *

* Sets the fully qualified name of the type to import the constant field values for. *

* * @param type The fully qualified name of the type to import the constant field values for. */ public void setType(final String type) { getStateHelper().put(PropertyKeys.type, type); } /** *

* Returns name of request scope attribute under which constants will be exposed as a Map. *

* * @return Name of request scope attribute under which constants will be exposed as a Map. */ public String getVar() { return (String) getStateHelper().eval(PropertyKeys.var); } /** *

* Sets name of request scope attribute under which constants will be exposed as a Map. *

* * @param var Name of request scope attribute under which constants will be exposed as a Map. */ public void setVar(final String var) { getStateHelper().put(PropertyKeys.var, var); } // --------------------------------------------------------------------------------------------- UIComponent Methods /** *

* Set the {@link ValueExpression} used to calculate the value for the specified attribute or property name, if any. If * a {@link ValueExpression} is set for the var property, throw an illegal argument exception. *

* * @throws IllegalArgumentException If name is one of id, parent, or * var. * @throws NullPointerException If name is null. */ @Override public void setValueExpression(String name, ValueExpression binding) { if (PropertyKeys.var.toString().equals(name)) { throw new IllegalArgumentException(name); } super.setValueExpression(name, binding); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy