SimpleEvaluationContext class
An evaluation context that only lets an expression read (and, if allowed, write) properties: the one to use for expressions that come from outside, such as a filter typed by a user or a field path sent by a client.
A StandardEvaluationContext lets an expression create objects, call
static methods and reach beans, which is dangerous for text you did
not write. Here T(...), new, @bean references and assignments to
variables always fail; properties can be assigned only in read-write
mode, and methods can be called only after
SimpleEvaluationContextBuilder.withInstanceMethods or
SimpleEvaluationContextBuilder.withMethodResolvers. Properties are
read on maps, @Introspected classes and core Dart types, as in the
standard context. Create one with forReadOnlyDataBinding,
forReadWriteDataBinding or forPropertyAccessors, then build().
// A search filter typed by a user: it may read, never change.
final context = SimpleEvaluationContext.forReadOnlyDataBinding()
.withRootObject({'name': 'Ada'})
.build();
SpelExpressionParser().parseExpression('name').getValue(context);
// 'Ada'
SpelExpressionParser().parseExpression("name = 'x'").getValue(context);
// throws SpelEvaluationException (notAssignable)
SpelExpressionParser().parseExpression('#v = 1').getValue(context);
// throws SpelEvaluationException (variableAssignmentNotSupported)
Spring (Java):
EvaluationContext context = SimpleEvaluationContext
.forReadOnlyDataBinding()
.withRootObject(root)
.build();
parser.parseExpression("name").getValue(context);
- Implemented types
Properties
- beanResolver → BeanResolver?
-
Looks up
@nameand&name, ornullwhen the context has no bean references (they then fail with EL1057E).no setteroverride -
constructorResolvers
→ List<
ConstructorResolver> -
The resolvers asked, in order, for
new Name(...); empty when the context does not allow constructors.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
-
indexAccessors
→ List<
IndexAccessor> -
The accessors asked, in order, for
target[index]when the target is not a list, map or string.final - isAssignmentEnabled → bool
-
Whether expressions may assign (
=,++,--) andExpression.setValuemay write; whenfalseboth fail withnotAssignable(EL1068E).final -
methodResolvers
→ List<
MethodResolver> -
The resolvers asked, in order, for
obj.method(...).final - operatorOverloader → OperatorOverloader
-
Gives arithmetic operators a meaning for operands with no built-in
rule.
no setteroverride
-
propertyAccessors
→ List<
PropertyAccessor> -
The accessors asked, in order, for
obj.property.final - rootObject → Object?
-
The object unprefixed names are read on (
namemeans#root.name) whengetValueis called without a root object.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- typeComparator → TypeComparator
-
Orders values for
<,<=,>,>=andbetween.no setteroverride - typeConverter → TypeConverter
-
Converts values: for
getValueAs, conditions, templates, indexes and method arguments.final - typeLocator → TypeLocator
-
Finds the types of
T(Name),new Name(...)andinstanceof.no setteroverride
Methods
-
assignVariable(
String name, Object? valueSupplier()) → Object? -
Always throws
variableAssignmentNotSupported(EL1080E): expressions in a simple context cannot assign variables. Variables set from code with setVariable can still be read.override -
lookupVariable(
String name) → Object? -
The value of variable
#name, ornullwhen unset. Registered functions are variables too.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setVariable(
String name, Object? value) → void -
Sets the variable
#nametovaluefrom Dart code, before the expression is evaluated.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
forPropertyAccessors(
List< PropertyAccessor> accessors) → SimpleEvaluationContextBuilder -
A builder for a context that reads properties only through
accessors, instead of MapAccessor, the introspection accessor and the built-in one; assignment is enabled (turn it off with SimpleEvaluationContextBuilder.withAssignmentDisabled). -
forReadOnlyDataBinding(
) → SimpleEvaluationContextBuilder - A builder for a context whose expressions can read properties but not assign them, for evaluating conditions or paths.
-
forReadWriteDataBinding(
) → SimpleEvaluationContextBuilder -
A builder for a context whose expressions can read and assign
properties (
Expression.setValueonaddress.city), for binding submitted fields to an object.