Details
-
Type:
Task
-
Status: Open (View Workflow)
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: 3.2.0.Alpha1
-
Component/s: Messages
-
Labels:None
-
Affects:Documentation (Ref Guide, User Guide, etc.), Release Notes
-
Patch Instructions:Provide an interpolator and align it with efforts in other Seam modules.
-
Estimated Difficulty:Medium
Description
Since Weld Extensions has adopted the EL expression resolver, it's fitting that it also provides an interpolator for strings containing EL expression.
Provide an interpolator that resolves EL expressions and position parameters in strings. This feature was available in Seam 2 [1]. Since it's not provided yet in Seam 3, we see it showing up as a utility in various modules, including the International [2] and REST [3] modules. We should consolidate this to a single, authoritative source.
It should probably be made an interface with implementations that process specific expression languages, such as EL. For instance, one implementation might interpret MVEL. Just an idea.
[1] http://anonsvn.jboss.org/repos/seam/branches/community/Seam_2_2/src/main/org/jboss/seam/core/Interpolator.java
[2] https://github.com/seam/international/raw/master/impl/src/main/java/org/jboss/seam/international/status/builder/Interpolator.java
[3] https://github.com/seam/rest/raw/master/impl/src/main/java/org/jboss/seam/rest/util/ExpressionLanguageInterpolator.java
Gliffy Diagrams
Issue Links
- relates to
-
SEAMREST-48
Remove Interpolator class
-
- Resolved
-
Hm, it turns out there may have been some confusion around what makes up a ValueExpression. A ValueExpression may contain any number of inline variable expressions mixed with literal text. So for this case, we don't need an interpolator. It's just a documentation (and test case) issue.
Assert.assertEquals("Cheetahs are fast", expressions.evaluateValueExpression("Cheetahs are #
{cheetah.speed}", String.class));
{1 + 1}Assert.assertEquals((Integer) 2, expressions.evaluateValueExpression("#
", Integer.class));
However, there are still reasons to provide an interpolator.
An interpolator would additionally handle replacing positional and named parameters. Positional parameters can be handled by passing the result through MessageFormat:
Assert.assertEquals("Jon has a score of 97", MessageFormat.format(expressions.evaluateValueExpression("#
{person.name} has a score of {0}", String.class), 97));In addition to encapsulating the MessageFormat usage, the interpolator can hides the cast of the evaluation result to a String. With the interpolator, this assertion simplifies to:
Assert.assertEquals("Jon has a score of 97", interpolator.interpolate("#{person.name}
has a score of
{0}", 97));
I'm unsure whether there is value in named parameters. Though for developers familiar with JPQL and Bean Validation, the experience would be similar:
Assert.assertEquals("Jon has a score of 97", InterpolatedStringBuilder.expressionString("#
{person.name}has a score of
{score}").setParameter("score", 97).interpolate());
This builder concept has already been prototyped in the international module, though with a slightly different focus. It's important to align.