velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Christian <si...@stoutstick.com>
Subject Re: Problems with ViewRenderTool
Date Mon, 13 Dec 2004 18:00:47 GMT
Hi Binu,

Well I now have tried out the ViewRenderTool and it seems to work just 
fine (Velocity 1.4, VelocityTools 1.2-dev). The following example assume 
that an instance of ViewRenderTool has been put in the context 
correctly, as '$render':

--------------------------------------------------------------------

#*
  Just doing some setup to get a Map instance for testing
  I _really_ wouldn't do this in RL
  *#
#set( $foo = $render.getClass().forName( "java.util.HashMap" 
).newInstance() )

#*
  Put something into the map. Not interested in the result and don't want
  to render it.
  *#
#set( $result = $foo.put( "bar", "abc" ) )

#*
  Set variables with the (non-evaluated as they're in single quotes)
  names of the object, the key in the map and a method name for the Map
  object
*#
#set( $obj = '$foo' )
#set( $prop = 'bar' )
#set( $method = 'size()' )

#*
  various evaluations
  *#
1. $render.eval( "${obj}.get( '$prop' )" )

2. $render.eval( "${obj}.${prop}" )

3. $render.eval( "${obj}.$prop" )

4. $render.eval( "$obj.$prop" )

5. $render.eval( "${obj}.$method" )

6. $render.eval( "$obj.$method" )


--------------------------------------------------------------------

The above renders as:

1. abc
2. abc
3. abc
4. abc
5. 1
6. 1

So I suspect your 'e' object isn't quite ready. Does it have a public 
method called getFoo() or a get() method which returns something for the 
key 'foo'?

- simon

Nadesan, Binu wrote:
> Hi All,
> 
> I tried using all these techniques with the render tool and nothing seems to
> work for me.
> 
> 1. $render.eval( "${e}.${text}" )
> 
> 2. #set($D = "$")
> #set($getText = "${D}e.$text")
> $render.eval($getText)
> 
> 3. #set($D = "$")
> $render.recurse("${D}e.$text")
> 
> Let's say that "foo" was the value of $text. And $e is the object
> In all the above cases, the final output is the string values of the object
> and the property "foo."
> 
> Something like 
> 
> "Billing.foo"
> "Shipping.foo"
> 
> If I type-in directly say $e.foo then I get the proper value. Like 
> "Billing"
> "Shipping"
> 

btw, yhis doesn't really look like the result I would expect - if $e 
renders as "Billing", $e.foo would typically render as something else..
> 
> 
> Regards...
> Binu Nadesan.
> (513) 612-2206.
> 
> 
> -----Original Message-----
> From: Simon Christian [mailto:sjc@xtian.org.uk] 
> Sent: Friday, December 10, 2004 4:46 PM
> To: Velocity Users List
> Subject: Re: Problems with ViewRenderTool
> 
> Hi Binu,
> 
> I think the problem is that the parsers is trying to evaluate "$e.$text" 
> all in one go. The documentation suggests encapsulating the varriables 
> i.e. $render.eval( "${e}.${text}" )
> 
> http://jakarta.apache.org/velocity/tools/view/ViewRenderTool.html#eval()
> 
> Never actually used this particular 'tool myself, but I think that 
> should solve the problem.
> 
> - simon
> 
> Nadesan, Binu wrote:
> 
>>Hi All,
>>
>>I have problem with the Velocity ViewRender tool. Please see the macro
>>below...
>>
>>The problem lies with the statement $render.eval("$e.$text")
>>
>>Here $e is an object and $text contains a string value that is a property
> 
> of
> 
>>the object.
>>
>>Some how the tool is  not able to return the value of the object property.
> 
> I
> 
>>am I missing something here....
>>
>>
>>#macro (selectcontrol $name $selected $list $id $text)
>>	#set($s="NULL" )
>>	#set($s=$selected )
>>	<select name="$name">
>>	#foreach ($e in $list )
>>	#set($v = $render.eval("$e.$id"))
>>	<option value="$v"#if("$v"=="$s")
>>selected="selected"#end>$render.eval("$e.$text")</option>
>>	#end
>>	</select>
>>#end
>>
>>Regards...
>>Binu Nadesan.
>>(513) 612-2206.
>>
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message