From: Lane S. <la...@op...> - 2005-12-02 03:12:55
|
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. >>> >>> >> > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log > files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ > Webmacro-devel mailing list > Web...@li... > https://lists.sourceforge.net/lists/listinfo/webmacro-devel > -- Lane Sharman Providing Private and SPAM-Free Email http://www.opendoors.com 858-755-2868 |