|
View:
New views
18 Messages
—
Rating Filter:
Alert me
|
|
|
simple problemhello everyone out there,thank you for your attention:
(1) #set($a=1) ## I want to output $a+1 which is 2 DIRECTLY,how? If no way ,I can use #set($a=$a+1) or #set($b=$a+1) instead,which is a little complicated. (2) #set($newline="hello\n") ## I want to include a new line charactor in a string varible,when output ,result in a new line,how? thank you. |
|
|
Re: simple problemHi, Use #set($a = $a + 1)
Correct me if Im wrong but if u use variable like this it would write "hello" on a single line, where is the problem?
#set($newline="hello") $newline |
|
|
Re: simple problemwe know this #set($a = $a + 1) will change $a which in some cases may not be preferable...but thanks anyway.
2009/7/20 Alexander <the.malkolm@...>
|
|
|
RE: simple problemHi,
Use $velocityCount in place where you need incremental value of some variable Eg: instead of, #set($a = 0) #foreach($mapping in $mappings) Do something.. #set($a = $a+1) <label for="journal-$a">Type something</label> Do it like: #foreach($mapping in $mappings) Do something.. <label for="journal- $velocityCount ">Type something </label> $velocityCount increase the value of variable incrementally, without having to use ($a= $a+1) I hope this helps! Thanks, Rupali _____ From: lanxiazhi [mailto:lanxiazhi@...] Sent: Monday, July 20, 2009 12:52 PM To: Velocity Users List Subject: Re: simple problem we know this #set($a = $a + 1) will change $a which in some cases may not be preferable...but thanks anyway. 2009/7/20 Alexander <the.malkolm@...> Hi, Use #set($a = $a + 1) Correct me if Im wrong but if u use variable like this it would write "hello" on a single line, where is the problem? #set($newline="hello") $newline |
|
|
Re: simple problemthanks Rupali,
I got this problem when I started to think that, can I simply output an expression like #{1+2+200000*3+$a} without a varible? 2009/7/20 Rupali Gupta <r.gupta1@...> > Hi, > > > > Use $velocityCount in place where you need incremental value of some > variable > > Eg: instead of, > > > > #set($a = 0) > > #foreach($mapping in $mappings) > > Do something.. > > #set($a = $a+1) > > > > <label for="journal-$a">Type something</label> > > > > Do it like: > > > > #foreach($mapping in $mappings) > > Do something.. > > <label for="journal- $velocityCount ">Type something </label> > > > > > > $velocityCount increase the value of variable incrementally, without having > to use ($a= $a+1) > > > > I hope this helps! > > > > Thanks, > > Rupali > > > > > > _____ > > From: lanxiazhi [mailto:lanxiazhi@...] > Sent: Monday, July 20, 2009 12:52 PM > To: Velocity Users List > Subject: Re: simple problem > > > > we know this #set($a = $a + 1) will change $a which in some cases may not > be > preferable...but thanks anyway. > > 2009/7/20 Alexander <the.malkolm@...> > > Hi, > > > > Use > > > > #set($a = $a + 1) > > > > Correct me if Im wrong but if u use variable like this it would write > "hello" on a single line, where is the problem? > > > > #set($newline="hello") > > $newline > > > > |
|
|
Re: simple problemHello,everyone,I work on the problem this whole afternoon...
finally,I decided to end this with a macro: #macro(expr $expression) #set($temp--='#set($temp---'+"=$expression)"+'$temp---') #evaluate($temp--) $temp--- #end #set($a=2) #expr("$a*100+200") which result in a 400. wait for an easier way from you . thanks 2009/7/20 lanxiazhi <lanxiazhi@...> > thanks Rupali, > I got this problem when I started to think that, can I simply output an > expression like #{1+2+200000*3+$a} without a varible? > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > Hi, >> >> >> >> Use $velocityCount in place where you need incremental value of some >> variable >> >> Eg: instead of, >> >> >> >> #set($a = 0) >> >> #foreach($mapping in $mappings) >> >> Do something.. >> >> #set($a = $a+1) >> >> >> >> <label for="journal-$a">Type something</label> >> >> >> >> Do it like: >> >> >> >> #foreach($mapping in $mappings) >> >> Do something.. >> >> <label for="journal- $velocityCount ">Type something </label> >> >> >> >> >> >> $velocityCount increase the value of variable incrementally, without >> having >> to use ($a= $a+1) >> >> >> >> I hope this helps! >> >> >> >> Thanks, >> >> Rupali >> >> >> >> >> >> _____ >> >> From: lanxiazhi [mailto:lanxiazhi@...] >> Sent: Monday, July 20, 2009 12:52 PM >> To: Velocity Users List >> Subject: Re: simple problem >> >> >> >> we know this #set($a = $a + 1) will change $a which in some cases may not >> be >> preferable...but thanks anyway. >> >> 2009/7/20 Alexander <the.malkolm@...> >> >> Hi, >> >> >> >> Use >> >> >> >> #set($a = $a + 1) >> >> >> >> Correct me if Im wrong but if u use variable like this it would write >> "hello" on a single line, where is the problem? >> >> >> >> #set($newline="hello") >> >> $newline >> >> >> >> > |
|
|
Re: simple problemYeah, but $velocityCount starts counting from 1 not from 0, don't it? Tricky
moment so. 2009/7/20 Rupali Gupta <r.gupta1@...> > Hi, > > > > Use $velocityCount in place where you need incremental value of some > variable > > Eg: instead of, > > > > #set($a = 0) > > #foreach($mapping in $mappings) > > Do something.. > > #set($a = $a+1) > > > > <label for="journal-$a">Type something</label> > > > > Do it like: > > > > #foreach($mapping in $mappings) > > Do something.. > > <label for="journal- $velocityCount ">Type something </label> > > > > > > $velocityCount increase the value of variable incrementally, without having > to use ($a= $a+1) > > > > I hope this helps! > > > > Thanks, > > Rupali > > > > > > _____ > > From: lanxiazhi [mailto:lanxiazhi@...] > Sent: Monday, July 20, 2009 12:52 PM > To: Velocity Users List > Subject: Re: simple problem > > > > we know this #set($a = $a + 1) will change $a which in some cases may not > be > preferable...but thanks anyway. > > 2009/7/20 Alexander <the.malkolm@...> > > Hi, > > > > Use > > > > #set($a = $a + 1) > > > > Correct me if Im wrong but if u use variable like this it would write > "hello" on a single line, where is the problem? > > > > #set($newline="hello") > > $newline > > > > |
|
|
Re: simple problemOn Mon, Jul 20, 2009 at 12:49 AM, lanxiazhi<lanxiazhi@...> wrote:
> thanks Rupali, > I got this problem when I started to think that, can I simply output an > expression like #{1+2+200000*3+$a} without a varible? The macro is fine. Alternately, you could add an instance of the MathTool (from VelocityTools) to your context and use that. ## this will have a newline char in it... #set($newline="hello ") and $velocityCount can be configured to start at any number: directive.foreach.counter.initial.value = 0 > 2009/7/20 Rupali Gupta <r.gupta1@...> > >> Hi, >> >> >> >> Use $velocityCount in place where you need incremental value of some >> variable >> >> Eg: instead of, >> >> >> >> #set($a = 0) >> >> #foreach($mapping in $mappings) >> >> Do something.. >> >> #set($a = $a+1) >> >> >> >> <label for="journal-$a">Type something</label> >> >> >> >> Do it like: >> >> >> >> #foreach($mapping in $mappings) >> >> Do something.. >> >> <label for="journal- $velocityCount ">Type something </label> >> >> >> >> >> >> $velocityCount increase the value of variable incrementally, without having >> to use ($a= $a+1) >> >> >> >> I hope this helps! >> >> >> >> Thanks, >> >> Rupali >> >> >> >> >> >> _____ >> >> From: lanxiazhi [mailto:lanxiazhi@...] >> Sent: Monday, July 20, 2009 12:52 PM >> To: Velocity Users List >> Subject: Re: simple problem >> >> >> >> we know this #set($a = $a + 1) will change $a which in some cases may not >> be >> preferable...but thanks anyway. >> >> 2009/7/20 Alexander <the.malkolm@...> >> >> Hi, >> >> >> >> Use >> >> >> >> #set($a = $a + 1) >> >> >> >> Correct me if Im wrong but if u use variable like this it would write >> "hello" on a single line, where is the problem? >> >> >> >> #set($newline="hello") >> >> $newline >> >> >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: simple problemMaybe you should find some class that can parse and evaluate math string
(like "1+2+3*3 + 8/2") andthen use it in macro? #macro(calc $expr) $mathHelper.calculate($expr) #end I see you are trying to write ur own parser and I dont think It is a good idea. There should be a lot of such classes in internet, as writing calculator is ordinary simple task for beginner, huh? 2009/7/20 lanxiazhi <lanxiazhi@...> > Hello,everyone,I work on the problem this whole afternoon... > finally,I decided to end this with a macro: > #macro(expr $expression) > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > #evaluate($temp--) > $temp--- > #end > #set($a=2) > #expr("$a*100+200") > > which result in a 400. > wait for an easier way from you . > thanks > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > thanks Rupali, > > I got this problem when I started to think that, can I simply output an > > expression like #{1+2+200000*3+$a} without a varible? > > > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > > > Hi, > >> > >> > >> > >> Use $velocityCount in place where you need incremental value of some > >> variable > >> > >> Eg: instead of, > >> > >> > >> > >> #set($a = 0) > >> > >> #foreach($mapping in $mappings) > >> > >> Do something.. > >> > >> #set($a = $a+1) > >> > >> > >> > >> <label for="journal-$a">Type something</label> > >> > >> > >> > >> Do it like: > >> > >> > >> > >> #foreach($mapping in $mappings) > >> > >> Do something.. > >> > >> <label for="journal- $velocityCount ">Type something </label> > >> > >> > >> > >> > >> > >> $velocityCount increase the value of variable incrementally, without > >> having > >> to use ($a= $a+1) > >> > >> > >> > >> I hope this helps! > >> > >> > >> > >> Thanks, > >> > >> Rupali > >> > >> > >> > >> > >> > >> _____ > >> > >> From: lanxiazhi [mailto:lanxiazhi@...] > >> Sent: Monday, July 20, 2009 12:52 PM > >> To: Velocity Users List > >> Subject: Re: simple problem > >> > >> > >> > >> we know this #set($a = $a + 1) will change $a which in some cases may > not > >> be > >> preferable...but thanks anyway. > >> > >> 2009/7/20 Alexander <the.malkolm@...> > >> > >> Hi, > >> > >> > >> > >> Use > >> > >> > >> > >> #set($a = $a + 1) > >> > >> > >> > >> Correct me if Im wrong but if u use variable like this it would write > >> "hello" on a single line, where is the problem? > >> > >> > >> > >> #set($newline="hello") > >> > >> $newline > >> > >> > >> > >> > > > |
|
|
Re: simple problemOh, didnt know that it can be configured, really thanks! Anyway default behaviour not obvious for javadev.
2009/7/20 Nathan Bubna <nbubna@...>
|
|
|
Re: simple problemOn Mon, Jul 20, 2009 at 7:02 AM, Alexander <the.malkolm@...> wrote:
> > Oh, didnt know that it can be configured, really thanks! Anyway default behaviour not obvious for javadev. The rational was that it wasn't just meant for javadevs and javadevs would be able to figure it out. I'm willing to reconsider this in version 2. > 2009/7/20 Nathan Bubna <nbubna@...> >> >> On Mon, Jul 20, 2009 at 12:49 AM, lanxiazhi<lanxiazhi@...> wrote: >> > thanks Rupali, >> > I got this problem when I started to think that, can I simply output an >> > expression like #{1+2+200000*3+$a} without a varible? >> >> The macro is fine. Alternately, you could add an instance of the >> MathTool (from VelocityTools) to your context and use that. >> >> ## this will have a newline char in it... >> #set($newline="hello >> ") >> >> and $velocityCount can be configured to start at any number: >> >> directive.foreach.counter.initial.value = 0 >> >> > 2009/7/20 Rupali Gupta <r.gupta1@...> >> > >> >> Hi, >> >> >> >> >> >> >> >> Use $velocityCount in place where you need incremental value of some >> >> variable >> >> >> >> Eg: instead of, >> >> >> >> >> >> >> >> #set($a = 0) >> >> >> >> #foreach($mapping in $mappings) >> >> >> >> Do something.. >> >> >> >> #set($a = $a+1) >> >> >> >> >> >> >> >> <label for="journal-$a">Type something</label> >> >> >> >> >> >> >> >> Do it like: >> >> >> >> >> >> >> >> #foreach($mapping in $mappings) >> >> >> >> Do something.. >> >> >> >> <label for="journal- $velocityCount ">Type something </label> >> >> >> >> >> >> >> >> >> >> >> >> $velocityCount increase the value of variable incrementally, without having >> >> to use ($a= $a+1) >> >> >> >> >> >> >> >> I hope this helps! >> >> >> >> >> >> >> >> Thanks, >> >> >> >> Rupali >> >> >> >> >> >> >> >> >> >> >> >> _____ >> >> >> >> From: lanxiazhi [mailto:lanxiazhi@...] >> >> Sent: Monday, July 20, 2009 12:52 PM >> >> To: Velocity Users List >> >> Subject: Re: simple problem >> >> >> >> >> >> >> >> we know this #set($a = $a + 1) will change $a which in some cases may not >> >> be >> >> preferable...but thanks anyway. >> >> >> >> 2009/7/20 Alexander <the.malkolm@...> >> >> >> >> Hi, >> >> >> >> >> >> >> >> Use >> >> >> >> >> >> >> >> #set($a = $a + 1) >> >> >> >> >> >> >> >> Correct me if Im wrong but if u use variable like this it would write >> >> "hello" on a single line, where is the problem? >> >> >> >> >> >> >> >> #set($newline="hello") >> >> >> >> $newline >> >> >> >> >> >> >> >> >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@... >> For additional commands, e-mail: user-help@... >> > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: simple problemI mean that always people say that you could use it in foreach statement and
gives completely incorrect example as we saw there. So I tried to stress that initial value default is 1 not 0. Sure javadev can figure it out, but with wrong example in front of eyes it would be mentally harder. 2009/7/20 Nathan Bubna <nbubna@...> > On Mon, Jul 20, 2009 at 7:02 AM, Alexander <the.malkolm@...> wrote: > > > > Oh, didnt know that it can be configured, really thanks! Anyway default > behaviour not obvious for javadev. > > The rational was that it wasn't just meant for javadevs and javadevs > would be able to figure it out. I'm willing to reconsider this in > version 2. > > > 2009/7/20 Nathan Bubna <nbubna@...> > >> > >> On Mon, Jul 20, 2009 at 12:49 AM, lanxiazhi<lanxiazhi@...> wrote: > >> > thanks Rupali, > >> > I got this problem when I started to think that, can I simply output > an > >> > expression like #{1+2+200000*3+$a} without a varible? > >> > >> The macro is fine. Alternately, you could add an instance of the > >> MathTool (from VelocityTools) to your context and use that. > >> > >> ## this will have a newline char in it... > >> #set($newline="hello > >> ") > >> > >> and $velocityCount can be configured to start at any number: > >> > >> directive.foreach.counter.initial.value = 0 > >> > >> > 2009/7/20 Rupali Gupta <r.gupta1@...> > >> > > >> >> Hi, > >> >> > >> >> > >> >> > >> >> Use $velocityCount in place where you need incremental value of some > >> >> variable > >> >> > >> >> Eg: instead of, > >> >> > >> >> > >> >> > >> >> #set($a = 0) > >> >> > >> >> #foreach($mapping in $mappings) > >> >> > >> >> Do something.. > >> >> > >> >> #set($a = $a+1) > >> >> > >> >> > >> >> > >> >> <label for="journal-$a">Type something</label> > >> >> > >> >> > >> >> > >> >> Do it like: > >> >> > >> >> > >> >> > >> >> #foreach($mapping in $mappings) > >> >> > >> >> Do something.. > >> >> > >> >> <label for="journal- $velocityCount ">Type something </label> > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> $velocityCount increase the value of variable incrementally, without > having > >> >> to use ($a= $a+1) > >> >> > >> >> > >> >> > >> >> I hope this helps! > >> >> > >> >> > >> >> > >> >> Thanks, > >> >> > >> >> Rupali > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> _____ > >> >> > >> >> From: lanxiazhi [mailto:lanxiazhi@...] > >> >> Sent: Monday, July 20, 2009 12:52 PM > >> >> To: Velocity Users List > >> >> Subject: Re: simple problem > >> >> > >> >> > >> >> > >> >> we know this #set($a = $a + 1) will change $a which in some cases may > not > >> >> be > >> >> preferable...but thanks anyway. > >> >> > >> >> 2009/7/20 Alexander <the.malkolm@...> > >> >> > >> >> Hi, > >> >> > >> >> > >> >> > >> >> Use > >> >> > >> >> > >> >> > >> >> #set($a = $a + 1) > >> >> > >> >> > >> >> > >> >> Correct me if Im wrong but if u use variable like this it would write > >> >> "hello" on a single line, where is the problem? > >> >> > >> >> > >> >> > >> >> #set($newline="hello") > >> >> > >> >> $newline > >> >> > >> >> > >> >> > >> >> > >> > > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: user-unsubscribe@... > >> For additional commands, e-mail: user-help@... > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > |
|
|
Re: simple problemYes,Alexander,and I google it,and i found one choice:jep.and maybe javacc is
another choice for this. by the way,besides evaluating math expression ,my macro can insert varibles in it. like expr("$a+100*$b"). still I think this is not a good way to do it,maybe next version of velocity will support this expression eval internally,which I think is not a hard task for the talented developers. the macro: #macro(expr $expression) #set($temp--='#set($temp---'+"=$expression)"+'$temp---') #evaluate($temp--) #end 2009/7/20 Alexander <the.malkolm@...> > Maybe you should find some class that can parse and evaluate math string > (like "1+2+3*3 + 8/2") andthen use it in macro? > > #macro(calc $expr) > $mathHelper.calculate($expr) > #end > > I see you are trying to write ur own parser and I dont think It is a good > idea. There should be a lot of > such classes in internet, as writing calculator is ordinary simple task for > beginner, huh? > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > Hello,everyone,I work on the problem this whole afternoon... > > finally,I decided to end this with a macro: > > #macro(expr $expression) > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > #evaluate($temp--) > > $temp--- > > #end > > #set($a=2) > > #expr("$a*100+200") > > > > which result in a 400. > > wait for an easier way from you . > > thanks > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > thanks Rupali, > > > I got this problem when I started to think that, can I simply output an > > > expression like #{1+2+200000*3+$a} without a varible? > > > > > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > > > > > Hi, > > >> > > >> > > >> > > >> Use $velocityCount in place where you need incremental value of some > > >> variable > > >> > > >> Eg: instead of, > > >> > > >> > > >> > > >> #set($a = 0) > > >> > > >> #foreach($mapping in $mappings) > > >> > > >> Do something.. > > >> > > >> #set($a = $a+1) > > >> > > >> > > >> > > >> <label for="journal-$a">Type something</label> > > >> > > >> > > >> > > >> Do it like: > > >> > > >> > > >> > > >> #foreach($mapping in $mappings) > > >> > > >> Do something.. > > >> > > >> <label for="journal- $velocityCount ">Type something </label> > > >> > > >> > > >> > > >> > > >> > > >> $velocityCount increase the value of variable incrementally, without > > >> having > > >> to use ($a= $a+1) > > >> > > >> > > >> > > >> I hope this helps! > > >> > > >> > > >> > > >> Thanks, > > >> > > >> Rupali > > >> > > >> > > >> > > >> > > >> > > >> _____ > > >> > > >> From: lanxiazhi [mailto:lanxiazhi@...] > > >> Sent: Monday, July 20, 2009 12:52 PM > > >> To: Velocity Users List > > >> Subject: Re: simple problem > > >> > > >> > > >> > > >> we know this #set($a = $a + 1) will change $a which in some cases may > > not > > >> be > > >> preferable...but thanks anyway. > > >> > > >> 2009/7/20 Alexander <the.malkolm@...> > > >> > > >> Hi, > > >> > > >> > > >> > > >> Use > > >> > > >> > > >> > > >> #set($a = $a + 1) > > >> > > >> > > >> > > >> Correct me if Im wrong but if u use variable like this it would write > > >> "hello" on a single line, where is the problem? > > >> > > >> > > >> > > >> #set($newline="hello") > > >> > > >> $newline > > >> > > >> > > >> > > >> > > > > > > |
|
|
Re: simple problemlanxiazhi,
> by the way,besides evaluating math expression ,my macro can insert > varibles in it. like expr("$a+100*$b"). Before you passing "$a + 100*$b" to method parameters Velocity automatically gonna replace all variables with values, remember? > #macro(calc $expr) $mathHelper.calculate($expr) #end $mathHelper.calculate("$a + 100*$b") 2009/7/20 lanxiazhi <lanxiazhi@...> > Yes,Alexander,and I google it,and i found one choice:jep.and maybe javacc > is > another choice for this. > by the way,besides evaluating math expression ,my macro can insert > varibles > in it. > like expr("$a+100*$b"). > still I think this is not a good way to do it,maybe next version of > velocity > will support this expression eval internally,which I think is not a hard > task for the talented developers. > the macro: > #macro(expr $expression) > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > #evaluate($temp--) > #end > 2009/7/20 Alexander <the.malkolm@...> > > > Maybe you should find some class that can parse and evaluate math string > > (like "1+2+3*3 + 8/2") andthen use it in macro? > > > > #macro(calc $expr) > > $mathHelper.calculate($expr) > > #end > > > > I see you are trying to write ur own parser and I dont think It is a good > > idea. There should be a lot of > > such classes in internet, as writing calculator is ordinary simple task > for > > beginner, huh? > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > Hello,everyone,I work on the problem this whole afternoon... > > > finally,I decided to end this with a macro: > > > #macro(expr $expression) > > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > > #evaluate($temp--) > > > $temp--- > > > #end > > > #set($a=2) > > > #expr("$a*100+200") > > > > > > which result in a 400. > > > wait for an easier way from you . > > > thanks > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > > > thanks Rupali, > > > > I got this problem when I started to think that, can I simply output > an > > > > expression like #{1+2+200000*3+$a} without a varible? > > > > > > > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > > > > > > > Hi, > > > >> > > > >> > > > >> > > > >> Use $velocityCount in place where you need incremental value of some > > > >> variable > > > >> > > > >> Eg: instead of, > > > >> > > > >> > > > >> > > > >> #set($a = 0) > > > >> > > > >> #foreach($mapping in $mappings) > > > >> > > > >> Do something.. > > > >> > > > >> #set($a = $a+1) > > > >> > > > >> > > > >> > > > >> <label for="journal-$a">Type something</label> > > > >> > > > >> > > > >> > > > >> Do it like: > > > >> > > > >> > > > >> > > > >> #foreach($mapping in $mappings) > > > >> > > > >> Do something.. > > > >> > > > >> <label for="journal- $velocityCount ">Type something </label> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> $velocityCount increase the value of variable incrementally, without > > > >> having > > > >> to use ($a= $a+1) > > > >> > > > >> > > > >> > > > >> I hope this helps! > > > >> > > > >> > > > >> > > > >> Thanks, > > > >> > > > >> Rupali > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> _____ > > > >> > > > >> From: lanxiazhi [mailto:lanxiazhi@...] > > > >> Sent: Monday, July 20, 2009 12:52 PM > > > >> To: Velocity Users List > > > >> Subject: Re: simple problem > > > >> > > > >> > > > >> > > > >> we know this #set($a = $a + 1) will change $a which in some cases > may > > > not > > > >> be > > > >> preferable...but thanks anyway. > > > >> > > > >> 2009/7/20 Alexander <the.malkolm@...> > > > >> > > > >> Hi, > > > >> > > > >> > > > >> > > > >> Use > > > >> > > > >> > > > >> > > > >> #set($a = $a + 1) > > > >> > > > >> > > > >> > > > >> Correct me if Im wrong but if u use variable like this it would > write > > > >> "hello" on a single line, where is the problem? > > > >> > > > >> > > > >> > > > >> #set($newline="hello") > > > >> > > > >> $newline > > > >> > > > >> > > > >> > > > >> > > > > > > > > > > |
|
|
Re: simple problemhello,try it this way,with single quote,
#expr('$a+$b*300') which works as expected. 2009/7/20 Alexander <the.malkolm@...> > lanxiazhi, > > > > by the way,besides evaluating math expression ,my macro can insert > > varibles in it. > > like expr("$a+100*$b"). > > > Before you passing "$a + 100*$b" to method parameters Velocity > automatically > gonna replace all variables with values, remember? > > > #macro(calc $expr) > > $mathHelper.calculate($expr) > > #end > > > $mathHelper.calculate("$a + 100*$b") > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > Yes,Alexander,and I google it,and i found one choice:jep.and maybe javacc > > is > > another choice for this. > > by the way,besides evaluating math expression ,my macro can insert > > varibles > > in it. > > like expr("$a+100*$b"). > > still I think this is not a good way to do it,maybe next version of > > velocity > > will support this expression eval internally,which I think is not a hard > > task for the talented developers. > > the macro: > > #macro(expr $expression) > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > #evaluate($temp--) > > #end > > 2009/7/20 Alexander <the.malkolm@...> > > > > > Maybe you should find some class that can parse and evaluate math > string > > > (like "1+2+3*3 + 8/2") andthen use it in macro? > > > > > > #macro(calc $expr) > > > $mathHelper.calculate($expr) > > > #end > > > > > > I see you are trying to write ur own parser and I dont think It is a > good > > > idea. There should be a lot of > > > such classes in internet, as writing calculator is ordinary simple task > > for > > > beginner, huh? > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > > > Hello,everyone,I work on the problem this whole afternoon... > > > > finally,I decided to end this with a macro: > > > > #macro(expr $expression) > > > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > > > #evaluate($temp--) > > > > $temp--- > > > > #end > > > > #set($a=2) > > > > #expr("$a*100+200") > > > > > > > > which result in a 400. > > > > wait for an easier way from you . > > > > thanks > > > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > > > > > thanks Rupali, > > > > > I got this problem when I started to think that, can I simply > output > > an > > > > > expression like #{1+2+200000*3+$a} without a varible? > > > > > > > > > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > > > > > > > > > Hi, > > > > >> > > > > >> > > > > >> > > > > >> Use $velocityCount in place where you need incremental value of > some > > > > >> variable > > > > >> > > > > >> Eg: instead of, > > > > >> > > > > >> > > > > >> > > > > >> #set($a = 0) > > > > >> > > > > >> #foreach($mapping in $mappings) > > > > >> > > > > >> Do something.. > > > > >> > > > > >> #set($a = $a+1) > > > > >> > > > > >> > > > > >> > > > > >> <label for="journal-$a">Type something</label> > > > > >> > > > > >> > > > > >> > > > > >> Do it like: > > > > >> > > > > >> > > > > >> > > > > >> #foreach($mapping in $mappings) > > > > >> > > > > >> Do something.. > > > > >> > > > > >> <label for="journal- $velocityCount ">Type something </label> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> $velocityCount increase the value of variable incrementally, > without > > > > >> having > > > > >> to use ($a= $a+1) > > > > >> > > > > >> > > > > >> > > > > >> I hope this helps! > > > > >> > > > > >> > > > > >> > > > > >> Thanks, > > > > >> > > > > >> Rupali > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> _____ > > > > >> > > > > >> From: lanxiazhi [mailto:lanxiazhi@...] > > > > >> Sent: Monday, July 20, 2009 12:52 PM > > > > >> To: Velocity Users List > > > > >> Subject: Re: simple problem > > > > >> > > > > >> > > > > >> > > > > >> we know this #set($a = $a + 1) will change $a which in some cases > > may > > > > not > > > > >> be > > > > >> preferable...but thanks anyway. > > > > >> > > > > >> 2009/7/20 Alexander <the.malkolm@...> > > > > >> > > > > >> Hi, > > > > >> > > > > >> > > > > >> > > > > >> Use > > > > >> > > > > >> > > > > >> > > > > >> #set($a = $a + 1) > > > > >> > > > > >> > > > > >> > > > > >> Correct me if Im wrong but if u use variable like this it would > > write > > > > >> "hello" on a single line, where is the problem? > > > > >> > > > > >> > > > > >> > > > > >> #set($newline="hello") > > > > >> > > > > >> $newline > > > > >> > > > > >> > > > > >> > > > > >> > > > > > > > > > > > > > > > |
|
|
Re: simple problemI meant passing such string without single quote to method as parameter
eventually leads to same result: variables replaced with values and expression calculated. But using some math helper class is more flexible than writing your own macros. 2009/7/20 lanxiazhi <lanxiazhi@...> > hello,try it this way,with single quote, > #expr('$a+$b*300') > which works as expected. > > 2009/7/20 Alexander <the.malkolm@...> > > > lanxiazhi, > > > > > > > by the way,besides evaluating math expression ,my macro can insert > > > varibles in it. > > > > like expr("$a+100*$b"). > > > > > > Before you passing "$a + 100*$b" to method parameters Velocity > > automatically > > gonna replace all variables with values, remember? > > > > > #macro(calc $expr) > > > > $mathHelper.calculate($expr) > > > > #end > > > > > > $mathHelper.calculate("$a + 100*$b") > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > Yes,Alexander,and I google it,and i found one choice:jep.and maybe > javacc > > > is > > > another choice for this. > > > by the way,besides evaluating math expression ,my macro can insert > > > varibles > > > in it. > > > like expr("$a+100*$b"). > > > still I think this is not a good way to do it,maybe next version of > > > velocity > > > will support this expression eval internally,which I think is not a > hard > > > task for the talented developers. > > > the macro: > > > #macro(expr $expression) > > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > > #evaluate($temp--) > > > #end > > > 2009/7/20 Alexander <the.malkolm@...> > > > > > > > Maybe you should find some class that can parse and evaluate math > > string > > > > (like "1+2+3*3 + 8/2") andthen use it in macro? > > > > > > > > #macro(calc $expr) > > > > $mathHelper.calculate($expr) > > > > #end > > > > > > > > I see you are trying to write ur own parser and I dont think It is a > > good > > > > idea. There should be a lot of > > > > such classes in internet, as writing calculator is ordinary simple > task > > > for > > > > beginner, huh? > > > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > > > > > Hello,everyone,I work on the problem this whole afternoon... > > > > > finally,I decided to end this with a macro: > > > > > #macro(expr $expression) > > > > > #set($temp--='#set($temp---'+"=$expression)"+'$temp---') > > > > > #evaluate($temp--) > > > > > $temp--- > > > > > #end > > > > > #set($a=2) > > > > > #expr("$a*100+200") > > > > > > > > > > which result in a 400. > > > > > wait for an easier way from you . > > > > > thanks > > > > > > > > > > 2009/7/20 lanxiazhi <lanxiazhi@...> > > > > > > > > > > > thanks Rupali, > > > > > > I got this problem when I started to think that, can I simply > > output > > > an > > > > > > expression like #{1+2+200000*3+$a} without a varible? > > > > > > > > > > > > 2009/7/20 Rupali Gupta <r.gupta1@...> > > > > > > > > > > > > Hi, > > > > > >> > > > > > >> > > > > > >> > > > > > >> Use $velocityCount in place where you need incremental value of > > some > > > > > >> variable > > > > > >> > > > > > >> Eg: instead of, > > > > > >> > > > > > >> > > > > > >> > > > > > >> #set($a = 0) > > > > > >> > > > > > >> #foreach($mapping in $mappings) > > > > > >> > > > > > >> Do something.. > > > > > >> > > > > > >> #set($a = $a+1) > > > > > >> > > > > > >> > > > > > >> > > > > > >> <label for="journal-$a">Type something</label> > > > > > >> > > > > > >> > > > > > >> > > > > > >> Do it like: > > > > > >> > > > > > >> > > > > > >> > > > > > >> #foreach($mapping in $mappings) > > > > > >> > > > > > >> Do something.. > > > > > >> > > > > > >> <label for="journal- $velocityCount ">Type something </label> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> $velocityCount increase the value of variable incrementally, > > without > > > > > >> having > > > > > >> to use ($a= $a+1) > > > > > >> > > > > > >> > > > > > >> > > > > > >> I hope this helps! > > > > > >> > > > > > >> > > > > > >> > > > > > >> Thanks, > > > > > >> > > > > > >> Rupali > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> _____ > > > > > >> > > > > > >> From: lanxiazhi [mailto:lanxiazhi@...] > > > > > >> Sent: Monday, July 20, 2009 12:52 PM > > > > > >> To: Velocity Users List > > > > > >> Subject: Re: simple problem > > > > > >> > > > > > >> > > > > > >> > > > > > >> we know this #set($a = $a + 1) will change $a which in some > cases > > > may > > > > > not > > > > > >> be > > > > > >> preferable...but thanks anyway. > > > > > >> > > > > > >> 2009/7/20 Alexander <the.malkolm@...> > > > > > >> > > > > > >> Hi, > > > > > >> > > > > > >> > > > > > >> > > > > > >> Use > > > > > >> > > > > > >> > > > > > >> > > > > > >> #set($a = $a + 1) > > > > > >> > > > > > >> > > > > > >> > > > > > >> Correct me if Im wrong but if u use variable like this it would > > > write > > > > > >> "hello" on a single line, where is the problem? > > > > > >> > > > > > >> > > > > > >> > > > > > >> #set($newline="hello") > > > > > >> > > > > > >> $newline > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > > > > > > > > > > > > > > > > > |
|
|
Re: simple problemok,you're right,now i got what you mean. just a moment ago,I realized that I need no such math helper or such compicated macro as I wrote at all.If I have a velocity tool class called Simple,which contains a method :
double f(double d) {return d}; then I can use it in the template:$Simple.f($a+100*$b).This should work,I think.2009/7/20 Alexander <the.malkolm@...> I meant passing such string without single quote to method as parameter |
|
|
Re: simple problemI did it in the same way in my projects, and I defined class MathHelper just using Velocity:)
public Object calculate(String expr) { String vtl = "#set($_ooo=" + expr + ")"; VelocityContext vc = ... Velocity.evaluate... return vc.get("_ooo"); } ---bluejoe ----- Original Message ----- From: "Alexander" <the.malkolm@...> To: "Velocity Users List" <user@...> Sent: Monday, July 20, 2009 9:59 PM Subject: Re: simple problem > Maybe you should find some class that can parse and evaluate math string > (like "1+2+3*3 + 8/2") andthen use it in macro? > > #macro(calc $expr) > $mathHelper.calculate($expr) > #end > > I see you are trying to write ur own parser and I dont think It is a good > idea. There should be a lot of > such classes in internet, as writing calculator is ordinary simple task for > beginner, huh? > > 2009/7/20 lanxiazhi <lanxiazhi@...> > >> Hello,everyone,I work on the problem this whole afternoon... >> finally,I decided to end this with a macro: >> #macro(expr $expression) >> #set($temp--='#set($temp---'+"=$expression)"+'$temp---') >> #evaluate($temp--) >> $temp--- >> #end >> #set($a=2) >> #expr("$a*100+200") >> >> which result in a 400. >> wait for an easier way from you . >> thanks >> >> 2009/7/20 lanxiazhi <lanxiazhi@...> >> >> > thanks Rupali, >> > I got this problem when I started to think that, can I simply output an >> > expression like #{1+2+200000*3+$a} without a varible? >> > >> > 2009/7/20 Rupali Gupta <r.gupta1@...> >> > >> > Hi, >> >> >> >> >> >> >> >> Use $velocityCount in place where you need incremental value of some >> >> variable >> >> >> >> Eg: instead of, >> >> >> >> >> >> >> >> #set($a = 0) >> >> >> >> #foreach($mapping in $mappings) >> >> >> >> Do something.. >> >> >> >> #set($a = $a+1) >> >> >> >> >> >> >> >> <label for="journal-$a">Type something</label> >> >> >> >> >> >> >> >> Do it like: >> >> >> >> >> >> >> >> #foreach($mapping in $mappings) >> >> >> >> Do something.. >> >> >> >> <label for="journal- $velocityCount ">Type something </label> >> >> >> >> >> >> >> >> >> >> >> >> $velocityCount increase the value of variable incrementally, without >> >> having >> >> to use ($a= $a+1) >> >> >> >> >> >> >> >> I hope this helps! >> >> >> >> >> >> >> >> Thanks, >> >> >> >> Rupali >> >> >> >> >> >> >> >> >> >> >> >> _____ >> >> >> >> From: lanxiazhi [mailto:lanxiazhi@...] >> >> Sent: Monday, July 20, 2009 12:52 PM >> >> To: Velocity Users List >> >> Subject: Re: simple problem >> >> >> >> >> >> >> >> we know this #set($a = $a + 1) will change $a which in some cases may >> not >> >> be >> >> preferable...but thanks anyway. >> >> >> >> 2009/7/20 Alexander <the.malkolm@...> >> >> >> >> Hi, >> >> >> >> >> >> >> >> Use >> >> >> >> >> >> >> >> #set($a = $a + 1) >> >> >> >> >> >> >> >> Correct me if Im wrong but if u use variable like this it would write >> >> "hello" on a single line, where is the problem? >> >> >> >> >> >> >> >> #set($newline="hello") >> >> >> >> $newline >> >> >> >> >> >> >> >> >> > >> > |
| Free embeddable forum powered by Nabble | Forum Help |