From: Keats K. <ke...@xa...> - 2005-12-02 02:46:39
|
I agree. The more I think about it, the more I think it makes sense the way it is. I like that you can do stuff like: #setprops $List { #set baseDir="/export/accounts/" #set $i=0 #foreach $Account in $AccountList { #set $i=$i+1 Account$i=\$Account.Number Holder$i=\$Account.Holder File$i=\$baseDir\$Account.File } Count=$i } I'll try to update the Wiki page this weekend. Keats Lane Sharman wrote: > Hi Keats, > > Let's document the way that it is and work with it for a while. As > long as I can escape evaluation, then i have a working solution. > Solving it may induce other side effects we have not thought of. I > like the fact that you can complete evaluation. > > -Lane > > Keats Kirsch wrote: > >> Lane, >> >> Thanks for finding this. It's not strictly a "bug", but it is >> undocumented, and maybe undesirable, behavior. >> >> First of all, the workaround is to escape the $ char, i.e., >> >> #bean $Time = "java.util.Date" >> #setprops $Duration class="com.opendoors.entity.fundamental.Duration" >> { >> Start = \$Variable.get("Time") >> End = \$Variable.get("Time") >> } >> >> or more simply: >> >> #bean $Time = "java.util.Date" >> #setprops $Duration class="com.opendoors.entity.fundamental.Duration" >> { >> Start = \$Time >> End = \$Time >> } >> >> The reason for this is that the block argument of #setprops is >> evaluated prior to assigning the properties. The idea of this is to >> allow you to intermix directives and property assignments. E.g., >> >> #setprops $Obj { >> Count1: $x >> #set $x = $x + 1 >> Count2: $x >> } >> >> This works fine with Strings and ints, but for other types you will >> see the problem that you experienced. In your case, the dates were >> expanded into Strings, which then could not be assigned to a Date >> property. >> >> I'm not sure which trade-off is preferable; unescaped variable syntax >> or disallowing directives. I suppose we could add an option, like >> "as macro" with #setblock, to give the user a choice. Something >> like, "#setprops noeval ..." >> >> What do you think? >> >> Keats >> >> Lane Sharman wrote: >> >>> #bean $Time = "java.util.Date" >>> #bean $Duration = "com.opendoors.entity.fundamental.Duration" onNew >>> { >>> #set $Duration.Start = $Variable.get("Time") >>> #set $Duration.End = $Variable.get("Time") >>> #set $Duration.End = $Time >>> } >>> >>> >>> works fine. >>> >>> so there is a bug in the #setprops unless this is a "feature", >>> converting all RHS evaluations to string. >>> >>> -Lane >>> >>> Lane Sharman wrote: >>> >>>> is the RHS term always evaluated as a String before the assignment? >>>> What can I do to make an assigment of an object? >>>> >>>> #bean $Time = "java.util.Date" >>>> #setprops $Duration class="com.opendoors.entity.fundamental.Duration" >>>> { >>>> Start = $Variable.get("Time") >>>> End = $Variable.get("Time") >>>> } >>>> >>>> >>>> generates this error: >>>> >>>> 4:40:52 PM template ERROR Error parsing template: >>>> StringTemplate("unknown";"#set $Duration.Start=Fri Nov 25 16:40:53 >>>> PST 2005") >>>> org.webmacro.engine.ParseException: Parser Exception >>>> org.webmacro.parser.ParseException: Encountered "Fri" at line 1, >>>> column 22. >>> |