You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by carlo latasa <cl...@gmail.com> on 2008/12/03 18:28:36 UTC

Injecting properties into Velocity...

Hello

I'm trying to get velocity to use a properties file of mine that has
customized labels. This is so I can call a velocity tag like : #stextfield(
"label='member.username.label'" "name='username'" "size=25") where the label
value would be defined in the properties file.

Is it just a matter of putting the properties into some kind of static
Velocity class somewhere?

Thanks in advance,

Carlo

Re: Injecting properties into Velocity...

Posted by Thomas Vandahl <th...@medav.de>.
Nathan Bubna wrote:
> or you can use VelocityTools' ResourceTool class.  For this, you can
> either use the VelocityTools infrastructure to put it into the context
> or do something like:
> 
> context.put("text", new ResourceTool().bundle("labels"));
> 
> and then do
> 
> $text.username

We are using Velocity inside a Turbine application which does the same 
thing (Turbine pull tool, however). Does anyone have experience with 
managing these resources together with the template files?

We are currently trying to use the GNU gettext tools to keep the 
relation between the bundle and the template file but xgettext does not 
support the syntax "$l10n.key". Anyone having a better idea?

Bye, Thomas.


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


Re: Injecting properties into Velocity...

Posted by Thomas Vandahl <th...@tewisoft.de>.
Nathan Bubna wrote:
> or you can use VelocityTools' ResourceTool class.  For this, you can
> either use the VelocityTools infrastructure to put it into the context
> or do something like:
> 
> context.put("text", new ResourceTool().bundle("labels"));
> 
> and then do
> 
> $text.username

We are using Velocity inside a Turbine application which does the same
thing (Turbine pull tool, however). Does anyone have experience with
managing these resources together with the template files?

We are currently trying to use the GNU gettext tools to keep the
relation between the bundle and the template file but xgettext does not
support the syntax "$l10n.key". Anyone having a better idea?

Bye, Thomas.



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


Re: Injecting properties into Velocity...

Posted by Nathan Bubna <nb...@gmail.com>.
You can put a ResourceBundle directly into your context:

context.put("labels", ResourceBundle.getBundle("labels"));

and then do

$labels.getString('username')

or you can put a java.util.Properties in and just use $props.get('username')

or you can use VelocityTools' ResourceTool class.  For this, you can
either use the VelocityTools infrastructure to put it into the context
or do something like:

context.put("text", new ResourceTool().bundle("labels"));

and then do

$text.username


On Wed, Dec 3, 2008 at 9:28 AM, carlo latasa <cl...@gmail.com> wrote:
> Hello
>
> I'm trying to get velocity to use a properties file of mine that has
> customized labels. This is so I can call a velocity tag like : #stextfield(
> "label='member.username.label'" "name='username'" "size=25") where the label
> value would be defined in the properties file.
>
> Is it just a matter of putting the properties into some kind of static
> Velocity class somewhere?
>
> Thanks in advance,
>
> Carlo
>

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


Re: Injecting properties into Velocity...

Posted by carlo latasa <cl...@gmail.com>.
Hey Nathan,

I've figured it out... with the tag, using

"label = ... does not work.
"key = ... does work.

I guess it makes sense considering that the 'key' in the properties file is
what I'm trying to access.

Thanks for the help! Now I've got to figure out how to get the old tag
syntax working. Of the form #tag( TextField "label= ... where the label does
correctly lookup the property and the tag gets rendered. Again this use to
work in webwork 1.x

On Wed, Dec 3, 2008 at 12:24 PM, carlo latasa <cl...@gmail.com> wrote:

> Thanks again,
>
> However injecting the ResrouceBundle into the VelocityContext does not
> work. Perhaps it's because "label=.... invokes some special struts /
> velocity code?
>
> Carlo.
>
>
> On Wed, Dec 3, 2008 at 9:28 AM, carlo latasa <cl...@gmail.com> wrote:
>
>> Hello
>>
>> I'm trying to get velocity to use a properties file of mine that has
>> customized labels. This is so I can call a velocity tag like : #stextfield(
>> "label='member.username.label'" "name='username'" "size=25") where the label
>> value would be defined in the properties file.
>>
>> Is it just a matter of putting the properties into some kind of static
>> Velocity class somewhere?
>>
>> Thanks in advance,
>>
>> Carlo
>>
>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>



-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Re: Injecting properties into Velocity...

Posted by Nathan Bubna <nb...@gmail.com>.
How are you injecting it and how are you using it?

On Wed, Dec 3, 2008 at 12:24 PM, carlo latasa <cl...@gmail.com> wrote:
> Thanks again,
>
> However injecting the ResrouceBundle into the VelocityContext does not work.
> Perhaps it's because "label=.... invokes some special struts / velocity
> code?
>
> Carlo.
>
> On Wed, Dec 3, 2008 at 9:28 AM, carlo latasa <cl...@gmail.com> wrote:
>
>> Hello
>>
>> I'm trying to get velocity to use a properties file of mine that has
>> customized labels. This is so I can call a velocity tag like : #stextfield(
>> "label='member.username.label'" "name='username'" "size=25") where the label
>> value would be defined in the properties file.
>>
>> Is it just a matter of putting the properties into some kind of static
>> Velocity class somewhere?
>>
>> Thanks in advance,
>>
>> Carlo
>>
>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>

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


Re: Injecting properties into Velocity...

Posted by carlo latasa <cl...@gmail.com>.
Thanks again,

However injecting the ResrouceBundle into the VelocityContext does not work.
Perhaps it's because "label=.... invokes some special struts / velocity
code?

Carlo.

On Wed, Dec 3, 2008 at 9:28 AM, carlo latasa <cl...@gmail.com> wrote:

> Hello
>
> I'm trying to get velocity to use a properties file of mine that has
> customized labels. This is so I can call a velocity tag like : #stextfield(
> "label='member.username.label'" "name='username'" "size=25") where the label
> value would be defined in the properties file.
>
> Is it just a matter of putting the properties into some kind of static
> Velocity class somewhere?
>
> Thanks in advance,
>
> Carlo
>



-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567