Thank you again Nathan. We have already addressed the "ugly hack", and plugged up that potential hole. We won't be trying anything in that area.

We are installing 1.5 at this time, and will be applying your first solution.

gmc

Nathan Bubna wrote:
No, the map literal syntax is new to 1.5.  however, there are ugly,
dangerous hacks like this:

#set( $object = 0 )
#set( $personnelRecord =
$object.class.forName('java.util.HashMap').newInstance() )

but i can't in good conscience recommend that.  i think you should
just create a tool that returns new HashMaps on demand and put the
tool in the context.

public class MapMaker {
   public Map makeMap() {
       return new HashMap();
   }
}

context.put("mapMaker", new MapMaker());

#set( $personnelRecord = $mapMaker.makeMap() )
#set( $foo = $mapMaker.put('name', "...") )

and so on...

On 12/13/06, Gary M. Catlin <[EMAIL PROTECTED]> wrote:
Thank you Nathan.

I do not need a specific object type, but also am not using Velocity
1.5. Is there an equivalent syntax available in 1.4 to allow me to
create the map?

gmc


Nathan Bubna wrote:
> If you don't need a specific object type and are using Velocity 1.5,
> you can just use the new map syntax to create a map that you can add
> properties to.
>
> #set( $personnelRecord = { 'name' : "...",  'rank' : "...",
> 'serialNumber' : "..." } )
>
> if you need to create a specific object, i'd recommend creating a tool
> that instantiates new ones for you on demand and putting that tool in
> the context.
>
> #set( $personnelRecord = $myRecordMaker.createNewPersonnelRecord() )
>
> On 12/13/06, Gary M. Catlin <[EMAIL PROTECTED]> wrote:
>> How do I go about defining an object that possesses several properties,
>> so that the object may later be added to a list as follows:
>>
>> #set ($roster = [])
>>
>> #set ($personnelRecord.name = "...")
>> #set ($personnelRecord.rank = "...")
>> #set ($personnelRecord.serialNumber = "...")
>>
>> #set ($n = $roster.add($personnelRecord))
>>
>>
>> Obviously, I would be adding multiple records to "$roster" for later
>> retrieval.
>>
>> TIA
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to