[jboss-dev-forums] [Design of JBoss jBPM] - Variables in Mail Templates

magro1202 do-not-reply at jboss.com
Wed Jun 11 10:46:41 EDT 2008


Hi everyone 

I have tuned up a little the usage of variables in Mail Templates.

usually when you want to use a variable like that
 

  | <mail-templates>
  |   
  |   <variable name="defaultSubject" value="Mail" />
  |   
  |   <mail-template name='default'>
  |     <actors>#{taskInstance.actorId}</actors>
  |     <subject>#{defaultSubject}</subject>
  |     <text><![CDATA[Mail von Geppi:
  |       #{mailMessage}]]>
  |     </text>
  |   </mail-template>
  | 

the variable is evaluated correctly and the value of Subject is set to "Mail"

but if you want to use variable references within the variables like this


  | <mail-templates>
  | 
  |   <variable name="defaultSubject" value="[#{processDefinition.name} #{processInstance.id}] generated Mail" />
  |   
  |   <mail-template name='default'>
  |     <actors>#{taskInstance.actorId}</actors>
  |     <subject>#{defaultSubject}</subject>
  |     <text><![CDATA[Mail von Geppi:
  |       #{mailMessage}]]>
  |     </text>
  |   </mail-template>
  | 

the value within the variable is not evaluated.
So i added a loop which evaluates the variable value until all references are solved.

In class org.jbpm.mail.Mail:





  | public String getSubject() {
  |     if (subject==null) return null;
  |     Object parsedValue = null;
  |     String ret = subject;
  |     do {   	
  |     	ret = evaluate(ret);
  |     	ret = JbpmExpressionEvaluator.translateExpressionToDollars(ret);
  |         parsedValue = new ExpressionEvaluatorImpl().parseExpressionString(ret);
  |     } while (!(parsedValue instanceof String));   
  |     
  |     return ret;
  |   }
  | 
  |   public String getText() {
  |     if (text==null) return null;
  |     Object parsedValue = null;
  |     String ret = text;
  |     do {   	
  |     	ret = evaluate(ret);
  |     	ret = JbpmExpressionEvaluator.translateExpressionToDollars(ret);
  |         parsedValue = new ExpressionEvaluatorImpl().parseExpressionString(ret);
  |     } while (!(parsedValue instanceof String));   
  |     
  |     return ret;
  |   }
  | 

i will post a Jira Patch for this too

regards

Matthias 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4157398#4157398

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4157398



More information about the jboss-dev-forums mailing list