Thanks for the reply, I decided to not to implement the calculate method and place it in my model instead, so if a user needs a new calculation, I would have to hard code that.<div><br></div><div>What I am doing is creating a generic reporting tool, previously, for every financial institution, it requires a specific report to be sent back to the bank. There are over 50 of them (where each one is a big module of code itself) and they keep on expanding. I decided, as an experiment, to remove all the legacy code and use String template which is a single module to do what the other 50 modules has done. And it is working perfectly.</div>

<div><br></div><div>I was really sad when I wanted to break the model view separation, but I wanted to dynamically alter the model.</div><div><br></div><div>Thanks for all your help! I am going to stick with the strict model / view separation, and figure out different ways to generically do my task.</div>

<div><br></div><div>Regards,</div><div>Mohamed Mansour<br>
<br><br><div class="gmail_quote">On Mon, Aug 3, 2009 at 5:36 AM, Koerner, Ron <span dir="ltr">&lt;<a href="mailto:ron.koerner@wincor-nixdorf.com">ron.koerner@wincor-nixdorf.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Hi Mohamed,</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">actually it is the philosophy of StringTemplate that 
templates don&#39;t do calculations other than what is needed for display. So I 
fear it is not the right tool for your task, since you require something which 
builds a page model (all data displayed on the generated page) from your 
business model (all data the application provides) and something which generates 
a visible page from the page model.</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">StringTemplate only performs the latter job. If you want to 
use ST anyway you need to build something which takes some userdefined 
rules/calculations and generates a page model out of the business 
model.</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">If you prefer a very dirty hack: create an object 
like:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">class Calculator implements Map { public String get(String 
expr) { return eval(expr); }  /* implement dummies for the other operations 
*/ }</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Add a calculator to your page model:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">st.setAttribute(&quot;calc&quot;,new 
Calculator());</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Use the calculator in your template:</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">$calc.({$a$+$b$})$</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Just to make clear: this is a very very dirty hack and 
violates the StringTemplate philosophy in ways which could bring the wrath of 
the god(s) of model/view-separation upon you or me and may or may not turn the 
one who actually implements the above into an appropriate heap of 
dust.</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Also Terence might not invite you to dinner 
anymore...</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Regards,</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2">Ron</font></span></div>
<div dir="ltr" align="left"><span><font face="Arial" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left">
<hr>
</div>
<div dir="ltr" align="left"><font face="Tahoma" size="2"><b>From:</b> 
<a href="mailto:stringtemplate-interest-bounces@antlr.org" target="_blank">stringtemplate-interest-bounces@antlr.org</a> 
[mailto:<a href="mailto:stringtemplate-interest-bounces@antlr.org" target="_blank">stringtemplate-interest-bounces@antlr.org</a>] <b>On Behalf Of </b>Mohamed 
Mansour<br><b>Sent:</b> Friday, July 31, 2009 8:27 PM<br><b>To:</b> Jim 
Idle<br><b>Cc:</b> <a href="mailto:stringtemplate-interest@antlr.org" target="_blank">stringtemplate-interest@antlr.org</a><br><b>Subject:</b> Re: 
[stringtemplate-interest] How to use variables inside 
formatmodifiers<br></font><br></div><div><div></div><div class="h5">
<div></div>Hmm, that would be unfortunate. I can&#39;t use this kind of approach 
then. I am trying to create a generic &quot;Report&quot; where every user can do whatever 
they want with it. If they wanted to add 10 to the result to any variable, they 
could. But we can&#39;t do that with StringTemplate.
<div><br></div>
<div>I guess that is the limitation of StringTemplate.</div>
<div><br></div>
<div>Isn&#39;t there any way I can make it work, like a hack? A user can modify a 
variable by appending(adding) a number to it. (simply scenario)</div>
<div><br></div>
<div>Thanks,</div>
<div><br></div>
<div>-- Mohamed Mansour<br><br><br>
<div class="gmail_quote">On Fri, Jul 31, 2009 at 2:16 PM, Jim Idle <span dir="ltr">&lt;<a href="mailto:jimi@temporal-wave.com" target="_blank">jimi@temporal-wave.com</a>&gt;</span> 
wrote:<br>
<blockquote class="gmail_quote" style="padding-left:1ex;margin:0px 0px 0px 0.8ex;border-left:#ccc 1px solid">
  <div text="#000000" bgcolor="#ffffff">
  <div>
  <div></div>
  <div>Mohamed Mansour wrote: 
  <blockquote type="cite">
    <div class="gmail_quote">Hello, 
    <div><br></div>
    <div>I have been using StringTemplate to produce stylized report 
    files. Some variables need to be formatted someway, for example if I 
    want to uppercase a variable I do, therefore I setup an attribute 
    renderer:</div>
    <div><font face="&#39;courier new&#39;, monospace">$foo;format=&quot;uppercase&quot;$</font></div>
    <div><br></div>
    <div>In my specific case I would need to apply more than one formatter (more 
    than one attribute renderer for a variable), so I created many attribute 
    renders and I can process them like:</div>
    <div><font face="&#39;courier new&#39;, monospace">$foo;format=&quot;uppercase|fixedlength:10:x:R|lowercase&quot;$</font> 
    If you notice a modifer could have parameters ( with colons as seen with 
    fixedlength)</div>
    <div><br></div>
    <div>So if $foo is &quot;123aBc&quot; it will return &quot;XXXX123abc&quot;, the above works 
    perfectly fine</div>
    <div><br></div>
    <div>My main problem is that, some parameters in my format modifiers need to 
    be ST variables, for example, I would need to add a number:</div>
    <div><font face="&#39;courier new&#39;, monospace">$numA;format=&quot;calculate:+:$numB$&quot;$</font></div>
    <div><br></div>
    <div>If numA = 10, and numB = 5, the formatter will return15. But my problem 
    is that, it treats the variables as a string doesn&#39;t actually give me the 
    exact value of the variable.</div>
    <div><br></div>
    <div>How can I pass variables in the &quot;format&quot; 
  area?</div></div></blockquote></div></div>Calculations need to be performed 
  before setting the values in the templates otherwise you are breaking the 
  model/view separation that StringTemplate is as strict about as it can be. In 
  other words you should not be trying to do this.<br><br>The attribute renderer 
  while powerful, has to be used carefully so that you do not break this  
  separation as it is kind of a back door (the only way to close it would be to 
  implement a generic formatting engine and get rid of attribute renderers, but 
  that is a lot of code bloat of 
  course.<br><br>Jim<br></div><br>_______________________________________________<br>stringtemplate-interest 
  mailing list<br><a href="mailto:stringtemplate-interest@antlr.org" target="_blank">stringtemplate-interest@antlr.org</a><br><a href="http://www.antlr.org/mailman/listinfo/stringtemplate-interest" target="_blank">http://www.antlr.org/mailman/listinfo/stringtemplate-interest</a><br>

<br></blockquote></div><br></div>
</div></div><hr><font face="Arial" size="-2">WINCOR NIXDORF International GmbH <br>
Sitz der Gesellschaft: Paderborn <br>
Registergericht Paderborn HRB 3507<br>
Geschäftsführer: Eckard Heidloff (Vorsitzender), Stefan Auerbach, Dr. Jürgen Wunram<br>
Vorsitzender des Aufsichtsrats: Karl-Heinz Stiller <br>
Steuernummer: 339/5884/0020 - Ust-ID Nr.: DE812927716 - WEEE-Reg.-Nr. DE44477193<br>
<br>
Diese E-Mail enthält vertrauliche Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.<br>


<br>
This e-mail may contain confidential information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. <br>


</font>
</div>
</blockquote></div><br></div>