You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Mck <mi...@semb.wever.org> on 2010/03/10 09:54:51 UTC

wildcarding works in put-attribute@value but not in put-attribute@expression

w/ Tiles-2.2.2-SNAPSHOT.

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>

Is there a design reason this is not supported/implemented?
Otherwise, Is there a way to configure it to be so?
Otherwise, Will a patch to implement it be accepted?

~mck

Re: wildcarding works in put-attribute@value but not in put-attribute@expression

Posted by Mck <mi...@semb.wever.org>.
continued in https://issues.apache.org/jira/browse/TILES-502

~mck

Re: wildcarding works in put-attribute@value but not in put-attribute@expression

Posted by Mck <mi...@semb.wever.org>.
On Wed, 2010-03-10 at 09:54 +0100, Mck wrote:
> Otherwise, Will a patch to implement it be accepted?

For example this patch works for me...


--- tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java	(revision 921279)
+++ tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java	(working copy)
@@ -157,7 +157,9 @@
         nuattr.setRenderer(attr.getRenderer());
         Expression expressionObject = attr.getExpressionObject();
         if (expressionObject != null) {
-            nuattr.setExpressionObject(new Expression(expressionObject));
+            Expression newExpressionObject = Expression
+                    .createExpression(replace(expressionObject.getExpression(), vars), expressionObject.getLanguage());
+            nuattr.setExpressionObject(newExpressionObject);
         }
 
         Object value = attr.getValue();
@@ -207,6 +209,7 @@
      */
     private static String replace(String st, Object... vars) {
         if (st != null && st.indexOf('{') >= 0) {
+            st = st.replaceAll("'", "'''").replaceAll("\\Q${\\E", "\\$'{'");
             MessageFormat format = new MessageFormat(st, ROOT_LOCALE);
             return format.format(vars, new StringBuffer(), null).toString();
         }



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.

~mck