javax.el

Class ELProcessor


  • public class ELProcessor
    extends Object

    Provides an API for using EL in a stand-alone environment.

    This class provides a direct and simple interface for

    • Evaluating EL expressions.
    • Assigning values to beans or setting a bean property.
    • Setting a ValueExpression to a EL variable.
    • Defining a static method as an EL function.
    • Defining an object instance as an EL name.

    This API is not a replacement for the APIs in EL 2.2. Containers that maintains EL environments can continue to do so, without using this API.

    For EL users who want to manipulate EL environments, like adding custom ELResolvers, ELManager can be used.

    Scope and Life Cycle

    Since it maintains the state of the EL environments, ELProcessor is not thread safe. In the simplest case, an instance can be created and destroyed before and after evaluating EL expressions. A more general usage is to use an instance of ELProcessor for a session, so that the user can configure the EL evaluation environment for that session.

    Automatic Bracketing of Expressions

    A note about the EL expressions strings used in the class. The strings allowed in the methods getValue(java.lang.String, java.lang.Class<?>), setValue(java.lang.String, java.lang.Object), and setVariable(java.lang.String, java.lang.String) are limited to non-composite expressions, i.e. expressions of the form ${...} or #{...} only. Also, it is not necessary (in fact not allowed) to bracket the expression strings with ${ or #{ and } in these methods: they will be automatically bracketed. This reduces the visual cluster, without any lost of functionalities (thanks to the addition of the concatenation operator).

    Example

    The following code snippet illustrates the use of ELProcessor to define a bean and evaluate its property.
       ELProcessor elp = new ELProcessor();
       elp.defineBean("employee", new Employee("Charlie Brown"));
       String name = elp.eval("employee.name");
     
    Since:
    EL 3.0
    • Constructor Detail

      • ELProcessor

        public ELProcessor()
    • Method Detail

      • getELManager

        public ELManager getELManager()
        Return the ELManager used for EL processing.
        Returns:
        The ELManager used for EL processing.
      • eval

        public Object eval(String expression)
        Evaluates an EL expression.
        Parameters:
        expression - The EL expression to be evaluated.
        Returns:
        The result of the expression evaluation.
      • getValue

        public Object getValue(String expression,
                               Class<?> expectedType)
        Evaluates an EL expression, and coerces the result to the specified type.
        Parameters:
        expression - The EL expression to be evaluated.
        expectedType - Specifies the type that the resultant evaluation will be coerced to.
        Returns:
        The result of the expression evaluation.
      • setValue

        public void setValue(String expression,
                             Object value)
        Sets an expression with a new value. The target expression is evaluated, up to the last property resolution, and the resultant (base, property) pair is set to the provided value.
        Parameters:
        expression - The target expression
        value - The new value to set.
        Throws:
        PropertyNotFoundException - if one of the property resolutions failed because a specified variable or property does not exist or is not readable.
        PropertyNotWritableException - if the final variable or property resolution failed because the specified variable or property is not writable.
        ELException - if an exception was thrown while attempting to set the property or variable. The thrown exception must be included as the cause property of this exception, if available.
      • setVariable

        public void setVariable(String var,
                                String expression)
        Assign an EL expression to an EL variable. The expression is parsed, but not evaluated, and the parsed expression is mapped to the EL variable in the local variable map. Any previously assigned expression to the same variable will be replaced. If the expression is null, the variable will be removed.
        Parameters:
        var - The name of the variable.
        expression - The EL expression to be assigned to the variable.
      • defineFunction

        public void defineFunction(String prefix,
                                   String function,
                                   String className,
                                   String method)
                            throws ClassNotFoundException,
                                   NoSuchMethodException
        Define an EL function in the local function mapper.
        Parameters:
        prefix - The namespace for the function or "" for no namesapce.
        function - The name of the function. If empty (""), the method name is used as the function name.
        className - The full Java class name that implements the function.
        method - The name (specified without parenthesis) or the signature (as in the Java Language Spec) of the static method that implements the function. If the name (e.g. "sum") is given, the first declared method in class that matches the name is selected. If the signature (e.g. "int sum(int, int)" ) is given, then the declared method with the signature is selected.
        Throws:
        NullPointerException - if any of the arguments is null.
        ClassNotFoundException - if the specified class does not exists.
        NoSuchMethodException - if the method (with or without the signature) is not a declared method of the class, or if the method signature is not valid, or if the method is not a static method.
      • defineFunction

        public void defineFunction(String prefix,
                                   String function,
                                   Method method)
                            throws NoSuchMethodException
        Define an EL function in the local function mapper.
        Parameters:
        prefix - The namespace for the function or "" for no namesapce.
        function - The name of the function. If empty (""), the method name is used as the function name.
        method - The java.lang.reflect.Method instance of the method that implements the function.
        Throws:
        NullPointerException - if any of the arguments is null.
        NoSuchMethodException - if the method is not a static method
      • defineBean

        public void defineBean(String name,
                               Object bean)
        Define a bean in a local bean repository, hiding other beans of the same name.
        Parameters:
        name - The name of the bean
        bean - The bean instance to be defined. If null, the name will be removed from the local bean repository.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/el/elprocessor.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.