[
https://issues.apache.org/jira/browse/TILES-502?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12843672#action_12843672
]
Mck SembWever edited comment on TILES-502 at 3/10/10 7:16 PM:
--------------------------------------------------------------
It's not going to be entirely intuitive to users that they're required to
escape ${' characters relating to EL expressions.
And it breaks API (existing expressions will break in wildcarded definitions).
The alternative (trying to automatically escape it) can prove to be tricky
though.
One quick-win is that, AFAIK, only EL provides a possible combination of
literal string and expressions.
So a more robust solution (now tested) is to leave the replace method as-is but
to change replaceVarsInSimpleAttribute like:
if (expressionObject != null) {
Pattern elExpression = Pattern.compile("\\Q${\\E([^}]+)\\Q}\\E");
//@todo make static final constant
String result = expressionObject.getExpression();
Matcher m = elExpression.matcher(result);
result =
replace(elExpression.matcher(result).replaceAll("EL_EXPRESSION"), vars);
while(m.find()){
result = result.replaceFirst("EL_EXPRESSION", "\\${" +
m.group(1) + "}");
}
nuattr.setExpressionObject(Expression.createExpression(result,
expressionObject.getLanguage()));
}
Either way i'm happy though.
was (Author: michaelsembwever):
It's not going to be entirely intuitive to users that they're required to
escape ${' characters relating to EL expressions.
And it breaks API (existing expressions will break in wildcarded definitions).
The alternative (trying to automatically escape it) can prove to be tricky
though.
One quick-win is that, AFAIK, only EL provides a possible combination of
literal string and expressions.
So a more robust solution (but not tested) is to leave the replace method as-is
but to change replaceVarsInSimpleAttribute like:
if (expressionObject != null) {
String pattern = "\\Q${\\E([^}]+)\\Q}\\E";
String result = expressionObject.getExpression();
Matcher m = Pattern.compile(pattern).matcher(result);
m.find();
result = result.replaceAll(pattern, "EL_EXPRESSION");
result = replace(result, vars);
int group = 0;
while(result.contains("EL_EXPRESSION")){
result = result.replaceFirst("EL_EXPRESSION", m.group(++group));
}
nuattr.setExpressionObject(Expression.createExpression(result,
expressionObject.getLanguage()));
}
Either way i'm happy though.
> wildcarding works in put-attrib...@value but not in put-attrib...@expression
> -----------------------------------------------------------------------------
>
> Key: TILES-502
> URL: https://issues.apache.org/jira/browse/TILES-502
> Project: Tiles
> Issue Type: Bug
> Components: tiles-core
> Affects Versions: 2.2.2
> Reporter: Mck SembWever
> Fix For: 2.2.2
>
> Attachments: tiles-502.patch
>
>
> This works:
> <definition name="REGEXP:([^.]+)">
> <put-attribute name="something" value="some-{1}.jsp"
> </definition>
> but this does not:
> <definition name="REGEXP:([^.]+)">
> <put-attribute name="something"
> expression="some-{1}-${requestScope.someVariable}.jsp"
> </definition>
> Attached is a patch, albeit that
> st = st.replaceAll("'", "'''").replaceAll("\\Q${\\E", "\\$'{'");
> definitely should be improved with something from javax.el that escapes
> the el before pushing it through the MessageFormat.
> But going down this path it should be made pluggable so that the various
> registered attributeEvaluators are called to do the appropriate
> escaping.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.