You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "G.L. Grobe" <ga...@grobe.net> on 2002/02/19 02:00:05 UTC

i18n catalog

I use webwork along w/ velocity now and am wondering how to do the equal in
velocity as I did w/ webwork.

A tag like <webwork:text name="'main.bgcolor'"/> would do a lookup in an
i18n file and pull out the string ...
main.bgcolor=#FFFFCC

This way when I changed the bgcolor value, it would change throughout all my
pages.

Any help much appreciated.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: String comparison

Posted by Rodney Schneider <rl...@arcalink.com>.
On Wednesday 20 February 2002 10:01 am, you wrote:
> On 2/19/02 5:59 PM, "Rodney Schneider" <rl...@arcalink.com> wrote:
> > Hi,
> >
> > I know this has probably been asked a million times, but I can't seem to
> > find a straight answer in the docs or mailing list archives.  I am having
> > trouble getting String comparison working in my Velocity templates.
> > Here is some sample code I have for generating a select box with the
> > correct option selected:
> >
> > -------------------------
> > #set ($selected = $author.AuthorType)
> > #if (!$selected)
> > #set ($selected = "S")
> > #end
> >
> > <select name="author_type">
> > <option value="S"#if ($selected.equals("S"))
> > selected="1"#end>Student</option> <option value="T"#if
> > ($selected.equals("T")) selected="1"#end>Teacher</option> <option
> > value="O"#if ($selected.equals("O")) selected="1"#end>Other</option>
> > </select>
> > --------------------------
> >
> > I have also tried using:
> >
> > #if ($selected == "S") selected="1"#end
> >
> > But that doesn't seem to work either.  I have inserted html comments
> > into my template containing $selected, and it always prints out
> > correctly, but the code above still doesn't work.
> >
> > Any help would be greatly appreciated.
>
> What does $author.AuthorType return?

Sorry for the late reply... I've been busy on other stuff.  
$author.AuthorType should call author.getAuthorType() which returns a 
java.lang.String.

Thanks for your help,

-- Rodney

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


WYSIWYG editors

Posted by Shawn Church <sh...@boxity.com>.
I have always for the most part hand-coded html (including .vm and .wm
templates), but I am wondering if there is a quicker alternative.  I'm
through much of the Java coding for my most recent project, and I am just
beginning the trudge through the presentation layer.

Any opinions for or against a particular WYSIWYG editor is appreciated, and
of course it must at least tolerate the presence of embedded VTL.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Turning caching on

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/19/02 6:44 PM, "Darren Evenson" <DE...@safenetconsulting.com> wrote:

> Should I have anything to fear by turning caching on in production?

Fear itself?

> Are
> there any known issues where Velocity's behavior (output) is different based
> on whether caching is turned on or off?  I'm actually achieving acceptable
> performance without caching, but faster is always better.

It's faster.  I run cached.
 
> I'm using Velocity within my app to format email messages.  Unfortunately,
> for now, I'm locked into another templating language for my web pages :-)

Alas.  
 
> BTW, is there any way to take advantage of caching when the template comes
> from a String, rather than a file?

No, not yet.

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
The bytecodes are language independent. - Sam Ruby  


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Turning caching on

Posted by Darren Evenson <DE...@safenetconsulting.com>.
Should I have anything to fear by turning caching on in production?  Are
there any known issues where Velocity's behavior (output) is different based
on whether caching is turned on or off?  I'm actually achieving acceptable
performance without caching, but faster is always better.

I'm using Velocity within my app to format email messages.  Unfortunately,
for now, I'm locked into another templating language for my web pages :-)

BTW, is there any way to take advantage of caching when the template comes
from a String, rather than a file?

Thanks,
Darren A. Evenson

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: String comparison

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/19/02 5:59 PM, "Rodney Schneider" <rl...@arcalink.com> wrote:

> Hi,
> 
> I know this has probably been asked a million times, but I can't seem to
> find a straight answer in the docs or mailing list archives.  I am having
> trouble getting String comparison working in my Velocity templates.
> Here is some sample code I have for generating a select box with the
> correct option selected:
> 
> -------------------------
> #set ($selected = $author.AuthorType)
> #if (!$selected)
> #set ($selected = "S")
> #end
> 
> <select name="author_type">
> <option value="S"#if ($selected.equals("S")) selected="1"#end>Student</option>
> <option value="T"#if ($selected.equals("T")) selected="1"#end>Teacher</option>
> <option value="O"#if ($selected.equals("O")) selected="1"#end>Other</option>
> </select>
> --------------------------
> 
> I have also tried using:
> 
> #if ($selected == "S") selected="1"#end
> 
> But that doesn't seem to work either.  I have inserted html comments
> into my template containing $selected, and it always prints out
> correctly, but the code above still doesn't work.
> 
> Any help would be greatly appreciated.

What does $author.AuthorType return?

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Be a giant.  Take giant steps.  Do giant things...


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


String comparison

Posted by Rodney Schneider <rl...@arcalink.com>.
Hi,

I know this has probably been asked a million times, but I can't seem to
find a straight answer in the docs or mailing list archives.  I am having
trouble getting String comparison working in my Velocity templates.
Here is some sample code I have for generating a select box with the
correct option selected:

-------------------------
#set ($selected = $author.AuthorType)
#if (!$selected)
  #set ($selected = "S")
#end

<select name="author_type">
  <option value="S"#if ($selected.equals("S")) selected="1"#end>Student</option>
  <option value="T"#if ($selected.equals("T")) selected="1"#end>Teacher</option>
  <option value="O"#if ($selected.equals("O")) selected="1"#end>Other</option>
</select>
--------------------------

I have also tried using:

#if ($selected == "S") selected="1"#end

But that doesn't seem to work either.  I have inserted html comments
into my template containing $selected, and it always prints out
correctly, but the code above still doesn't work.

Any help would be greatly appreciated.

Thanks,

-- Rodney

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: i18n catalog

Posted by Bill Burton <bi...@progress.com>.
Hello,

Since you're asking about Velocity functionality relating to the
<webwork:text> tag you might get a better response on the webwork-user
mailing list.  But I'll take a stab at it ...

>From what I can tell, it doesn't appear the WebWork Velocity view has the
equivalent functionality of the <webwork:text> and <webwork:i18n> JSP
tags.

However ...

"G.L. Grobe" wrote:
> 
> I use webwork along w/ velocity now and am wondering how to do the equal in
> velocity as I did w/ webwork.
> 
> A tag like <webwork:text name="'main.bgcolor'"/> would do a lookup in an
> i18n file and pull out the string ...
> main.bgcolor=#FFFFCC
> 
> This way when I changed the bgcolor value, it would change throughout all my
> pages.

Since what you're doing above doesn't require resource bundles, a real
easy workaround is to create a velocity template and #parse it at the top
of your pages.  It might look something like this:

  ## globals.vm - global page variables
  #set($main_bgcolor = '#FFFFCC')
  etc.

Then, in your pages:
  #parse("globals.vm")
  ...
  <body bgcolor="$main_bgcolor" ...>

Hope this helps,
-Bill

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: i18n catalog

Posted by Bill Burton <bi...@progress.com>.
Hello,

"G.L. Grobe" wrote:
> 
> After seeing this, things became much clearer on what a velocity context
> tool is.
> So I did things this way to get some context experience w/ velocity and have
> the following questions ...  (if I do #set( $foo = "bar") ... $foo, it
> works, so I've got velocity installed right).
> 
> --- my template
>     ## shows exactly this on the web page, context code looks like below
>     $i18n.getValue('color1')
> 
>     ## no matter where I set the file resource loader path, always reports
> 'unable to find ...'
>     ## as I understand it, TEMPLATE_ROOT is on the same level as ./WEB-INF
>     #parse("_ui/select.vm")
> 
> --- velocity.properties
> resource.loader = file
> file.resource.loader.path = ../template, ../../template, /template,
> template, .

I'm assuming here that you're using Velocity from within WebWork ...

In the WebWork's webwork.properties, is this property:
  file.resource.loader.path = /

WebWorkVelocityServlet (which extends VelocityServlet), checks for this
value and sets it to the web app root for you.  If modify this property,
you're on your own.

-Bill

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: i18n catalog

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/19/02 8:04 PM, "G.L. Grobe" <ga...@grobe.net> wrote:

> After seeing this, things became much clearer on what a velocity context
> tool is.
> So I did things this way to get some context experience w/ velocity and have
> the following questions ...  (if I do #set( $foo = "bar") ... $foo, it
> works, so I've got velocity installed right).
> 
> --- my template
>   ## shows exactly this on the web page, context code looks like below
>   $i18n.getValue('color1')
> 
>   ## no matter where I set the file resource loader path, always reports
> 'unable to find ...'
>   ## as I understand it, TEMPLATE_ROOT is on the same level as ./WEB-INF
>   #parse("_ui/select.vm")

Working in a servlet?  Take a look at the example servlets in /examples,
specifically in sample_servlet2, which shows how to modify the file path at
runtime.

There also is a new loader in the -tools/view project that you might want to
look at.

> 
> --- velocity.properties
> resource.loader = file
> file.resource.loader.path = ../template, ../../template, /template,
> template, .

See the example code...  It shows how to take those and modify at init time

 
> --- my ex. Catalog tool
>  public Catalog() {
>     hmap.put("color1", "#000000");
>     hmap.put("color2", "#FFFFFF");
>    // todo: make resource bundles out of this
>     ctx.put("i18n", hmap);
>  }
> 
>  public String getValue(String key) {
>     if (hmap.containsKey(key))
>        return (String) hmap.get(key);
> 
>     return "Key not found!";
>  }
> 
> Any help much appreciated.
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting

Age and treachery will always triumph over youth and talent


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: i18n catalog

Posted by "G.L. Grobe" <ga...@grobe.net>.
After seeing this, things became much clearer on what a velocity context
tool is.
So I did things this way to get some context experience w/ velocity and have
the following questions ...  (if I do #set( $foo = "bar") ... $foo, it
works, so I've got velocity installed right).

--- my template
    ## shows exactly this on the web page, context code looks like below
    $i18n.getValue('color1')

    ## no matter where I set the file resource loader path, always reports
'unable to find ...'
    ## as I understand it, TEMPLATE_ROOT is on the same level as ./WEB-INF
    #parse("_ui/select.vm")

--- velocity.properties
resource.loader = file
file.resource.loader.path = ../template, ../../template, /template,
template, .

--- my ex. Catalog tool
   public Catalog() {
      hmap.put("color1", "#000000");
      hmap.put("color2", "#FFFFFF");
     // todo: make resource bundles out of this
      ctx.put("i18n", hmap);
   }

   public String getValue(String key) {
      if (hmap.containsKey(key))
         return (String) hmap.get(key);

      return "Key not found!";
   }

Any help much appreciated.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: i18n catalog

Posted by Anthony Eden <ae...@signaturedomains.com>.
Another possibility would be to use a framework which works with
Velocity (since WebWork really is a framework, as opposed to Velocity
which is a template language).  JPublish ( http://www.jpublish.org/ ) is
one such example, but there are others.  As a matter of fact, I believe
that Web Work works with Velocity.  Check
http://jakarta.apache.org/velocity/powered.html for other frameworks
which support Velocity.

Sincerely,
Anthony Eden

> -----Original Message-----
> From: Geir Magnusson Jr. [mailto:geirm@optonline.net] 
> Sent: Monday, February 18, 2002 8:23 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: i18n catalog
> 
> 
> On 2/18/02 8:00 PM, "G.L. Grobe" <ga...@grobe.net> wrote:
> 
> > I use webwork along w/ velocity now and am wondering how to do the 
> > equal in velocity as I did w/ webwork.
> > 
> > A tag like <webwork:text name="'main.bgcolor'"/> would do a 
> lookup in 
> > an i18n file and pull out the string ... main.bgcolor=#FFFFCC
> > 
> > This way when I changed the bgcolor value, it would change 
> throughout 
> > all my pages.
> > 
> > Any help much appreciated.
> > 
> 
> Make a context tool.  Make a Java class that has a method
> 
>  public String getValue( String key )
> 
> That returns the value of that key.
> 
> Then put that class in the context as 'yourTool' and in the template
> 
>   $yourTool.getValue( 'main.bgcolor' )
> 
> Will return to the template what you want.
> 
> This sounds like a trivial answer, and it is, but that's all 
> there is to it. The hard part is of course the i18n class 
> that does this, but I you could adapt the webwork code :)
> 
> geir
> 
> -- 
> Geir Magnusson Jr.                                     
> geirm@optonline.net
> System and Software Consulting
> The question is : What is a Mahnamahna?
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:velocity-user-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: i18n catalog

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 2/18/02 8:00 PM, "G.L. Grobe" <ga...@grobe.net> wrote:

> I use webwork along w/ velocity now and am wondering how to do the equal in
> velocity as I did w/ webwork.
> 
> A tag like <webwork:text name="'main.bgcolor'"/> would do a lookup in an
> i18n file and pull out the string ...
> main.bgcolor=#FFFFCC
> 
> This way when I changed the bgcolor value, it would change throughout all my
> pages.
> 
> Any help much appreciated.
> 

Make a context tool.  Make a Java class that has a method

 public String getValue( String key )

That returns the value of that key.

Then put that class in the context as 'yourTool' and in the template

  $yourTool.getValue( 'main.bgcolor' )

Will return to the template what you want.

This sounds like a trivial answer, and it is, but that's all there is to it.
The hard part is of course the i18n class that does this, but I you could
adapt the webwork code :)

geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
The question is : What is a Mahnamahna?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>