Re: Status of this project

2006-05-04 Thread Mike Kienenberger

On 5/4/06, dizzi [EMAIL PROTECTED] wrote:

Thx, with speed in which ive got answer i see that velocity is not dead :)

I have one more question (pretty much offtopic)
Im using eclipse, im curious which plugins are you using to develop
tomcat+struts+velocity applications or which you can recommend.
(it will be probably better reply to my email than this list)


Yeah, it's not so much dead as so stable as to not need to upgrade.  
I've been using 1.3.1 for years as has the Cayenne project.


I typically use VelocityUI/velocity editor or Veloeclipse (one is a
fork of the other).

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



Re: How to use DateTool

2006-04-04 Thread Mike Kienenberger
On 4/4/06, Dominik Bruhn [EMAIL PROTECTED] wrote:
 So how do I use this tool?

http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/DateTool.html

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



Re: Release of Velosurf 1.4

2006-03-12 Thread Mike Kienenberger
My Understanding (and I've never actually used it) is that it's a
direct view-to-database framework.

I've recommended velosurf in the past to someone who was trying to
convert a Cold Fusion project to j2ee as a first pass.

I've never looked at Torque, though.

On 3/12/06, Tom Schindl [EMAIL PROTECTED] wrote:
 What's the difference to projects already existing like e.g. torque,
 which also uses velocity?

 Tom

 Claude Brisson wrote:
  I'm pleased to anounce the release of Velosurf 1.4
 
  About : Velosurf is a thin but efficient database mapping tool meant to
  be used with Jakarta Velocity. Its aim is to generate a set of context
  variables that automatically map database tables and relationships,
  without the need for any recomplation.
 
  Changes : The main purpose of this release is to allow the use of POJOs
  (Plain Old Java Objects) as row instances. Getters and setters of those
  POJOs are discovered using Java reflection.
 
  Homepage: http://velosurf.sourceforge.net/
  List: http://lists.sourceforge.net/lists/listinfo/velosurf-devel
  Tarball:
  http://prdownloads.sourceforge.net/velosurf/velosurf-1.4.tgz?download
 


 -
 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]



Re: Background material on Template Engines?

2006-02-03 Thread Mike Kienenberger
Friday, February 3, 2006, 6:12:11 PM, Elmar Juergens wrote:
 However, for the thesis itself, I would like to write some background
 paragraphs on template engines, on topics like:

 - how did template engines evolve?

On 2/3/06, Daniel Dekany [EMAIL PROTECTED] wrote:
 Like, for example, Velocity was a me-too project after WebMacro due
 licensing issues with WebMacro. (So it's maybe a good idea to put this
 question on the list of some other template engines too, where the
 template engine was made because of technical reasons, rather than from
 political reasons.)

For what it's worth, here's an early template engine (wow, 10 years
old now!) I originally used.   When I switched from ObjC to Java, I
converted my templates to velocity fairly painlessly.

http://www.misckit.com/Documentation/IntroMiscMergeKit.htmld/index.html

Here's what appears to be current contact info for Don, although I
haven't talked with him in a few years :)  I'm pretty sure he'd be
happy to discuss template engine evolution, at least from his own
standpoint.

http://www.yacktman.org/don/

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



Re: Date Formatting

2006-01-17 Thread Mike Kienenberger
If you're using a standalone-application, you can just manually add
the tool to your context.

context.put(dateTool, new DateTool());

or you can write your own toolbox loader.

Note that I used the following in a struts application to create an
email toolbox, and it's also for v1.1, so it's only good as a
reference:

public VelocityContext getEmailToolboxContext() throws ChainedException
{
try
{
ServletContext servletContext = getServletContext();

/* check the servlet config for a toolbox */
String toolboxFile = /WEB-INF/email.toolbox.xml;

XMLToolboxManager mgr = null;
InputStream is = null;
try
{
// get the bits
is = servletContext.getResourceAsStream(toolboxFile);
if (toolboxFile != null)
{
// little fix up
if (!toolboxFile.startsWith(/))
{
toolboxFile = / + toolboxFile;
}

// get config file pathname
String pathname = servletContext.getRealPath(toolboxFile);

}
else
{
Velocity.info(VelocityViewServlet: No toolbox
entry in configuration.);
}


InputStream inputStreamFromToolboxFile = is;
// InputStream inputStreamFromToolboxFile = new
FileInputStream(toolbox.xml);

class MyToolboxManager extends XMLToolboxManager{};

mgr = new MyToolboxManager();
mgr.load(inputStreamFromToolboxFile);
}
finally
{
try
{
if (is != null)
{
is.close();
}
}
catch(Exception ee) {}
}
ToolboxContext toolCtx = mgr.getToolboxContext(null);
return new VelocityContext(toolCtx);
}
catch (Exception anException)
{
ChainedException newChainedException = new
ChainedException(anException, Unable to create Toolbox Context );
throw newChainedException;
}
}


On 1/17/06, Edward Song [EMAIL PROTECTED] wrote:
 Hi,

 I have been trying to get the generic velocity tools to work with my java
 application.
 The application sends out emails, and I am using Velocity to generate the
 HTML string to be sent in the email.

 The one thing I am looking to do is to have a java.util.Date object
 formatted for presentation.
 I saw and downloaded the velocity tools packages and added
 velocity-tools-generic-1.2.jar to my classpath.

 I then restarted my app and found that the DateTool still does not format
 the date.

 I take a look at the examples, and a lot of the examples use the
 VelocityViewServlet and pass in a parameter pointing to toolbox.xml.  My
 application is standalone and has no use for struts.  Without this
 configuration it seems that VelocityTools will not know where to look for
 toolbox.xml.
 How do I specify this location in a standalone application?

 Ed


 -Original Message-
 From: Edward Song [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, January 17, 2006 11:44 AM
 To: 'Velocity Users List'
 Subject: RE: Date Formatting

 Nevermind, found the DateTools.

 http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/g
 eneric/DateTool.html


 -Original Message-
 From: Edward Song [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, January 17, 2006 11:37 AM
 To: 'Velocity Users List'
 Subject: Date Formatting

 Hi all,
 Is there a way to perform simple date formatting from a date object within a
 velocity template?
 I haven't found anything in the user guide and developer guide about date
 formatting.

 I don't think that the developer should have to format the date and add it
 to the context.
 Shouldn't template editors have this capability?

 I would think that it exists, I just don't know where to look, can someone
 point me to the correct resource.

 Thanks for your time,
 Ed


 -
 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]



Re: How to put # in the string

2005-11-18 Thread Mike Kienenberger
The most reliable way to do this is to use

#set ($h = '#')

And then ${h} whenever you want a # to appear.  (or ${esc.h} without
the #set if you have the escape tool installed)

This works in all cases exactly as you'd expect.   Avoid using \ to
escape things -- it's not intuitively obvious how it works.

On 11/18/05, Will Glass-Husain [EMAIL PROTECTED] wrote:
 Velocity's silly escaping rules insist that you put the slash before a
 directive \#if
 but not before a # by itself.  Just leave off the slash.

 WILL

 - Original Message -
 From: Gérard BUNEL [EMAIL PROTECTED]
 To: velocity-user@jakarta.apache.org
 Sent: Friday, November 18, 2005 1:07 AM
 Subject: How to put # in the string


  Hello,
 
  I need to insert a # character in my template but doing so, like in
  example2 modified below, I get an Error:
 
 String s = We are using $project $name to render this.\\#;
 w = new StringWriter();
 
 try
 {
 Velocity.evaluate( context, w, mystring, s );
 }
 
  ParseErrorException : org.apache.velocity.exception.ParseErrorException:
  Lexical
  error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at
  line
  1, column 47.  Encountered: EOF after : 
 
  So how could I insert this character in my template ?
 
  --
  BUNEL Gerard - ATLANTIDE
  Consultant
  Tel. : +33 (0)2 98 05 43 21
  http://www.ago.fr/
  --
  Technopôle Brest Iroise
  Site du Vernis - CS 23866
  29238 Brest Cedex 3 - France
  Tel. : +33 (0)2 98 05 43 21
  Fax. : +33 (0)2 98 05 20 34
  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]



Re: Situation jsp versus vm

2005-11-17 Thread Mike Kienenberger
Have you tried:

#set ( $a = $request.getAttribute(a) )
#set ( $x = ${a}b )
#set ( $y = $request.getAttribute($x) );

Or just

#set ( $y = $request.getAttribute(${request.getAttribute(a)}b) );

On 11/17/05, Marcel de Koster [EMAIL PROTECTED] wrote:
 Hi,
 I want to use velocity, but I'm faced with a problem I don't know thie
 answer for:
  JSP:
 %
 String a = request.getAttribute(a).toString();
 String x = a + b;
 String y = request.getAttribute(x).toString();
 %
  Velocity:
 #set ($x = $a + b) -- doesn't work
 #set ($y = ???) -- how do I get a variable from the context if you do not
 yet know the name, since it depends on another variable value.

 --
 Met Vriendelijke Groet,

 Marcel de Koster



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



Re: how to use a macro along with onClick

2005-11-17 Thread Mike Kienenberger
Velocity is server-side web page generation.  It generates the data
you see when you use View Source.

What you want is to execute code client-side.   You'll need to write
javascript to execute code client-side.

On 11/17/05, jill han [EMAIL PROTECTED] wrote:
 I tried to use a macro along with onClick. I expected the macro will be
 called only after the image was clicked. However it did not turn out as
 the way I expected.  There are scripting error. When I looked at the
 source codes, onClick = ' Table . '

  a href='#' onClick = '#vlmacro($val $va2 $vaList)'
   img name='image' src='image.gif'/a

 Is there anyway to use a macro along with onClick?

 Thanks in advance.

 Jill


 -
 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]



Re: Is there a line continuation character in Velocity?

2005-11-17 Thread Mike Kienenberger
Well, it's a misnomer to call ## a line continuation character.   It's
a to-end-of-line comment character.

You can't use it to make velocity statements into multiline statements.
You can only use it to make literal text into multiline literal text.

On 11/17/05, Glenn Holmer [EMAIL PROTECTED] wrote:
 On Thursday 10 November 2005 08:43, Mike Kienenberger wrote:
  Yes, ## comments out the newline and any other trailing text.

 I can't get that to work.  I have:

 $text.get(label.labelsPrinted, ##
   [$purchaseOrder.formattedLabelsPrintedDate])

 but I get an error:

 Encountered ##\n at line 91, column 40. Was expecting one of:
 [ ...  ... true ... false ...  ...  ... { ...

 What am I doing wrong?

 --
 
 Glenn Holmer  [EMAIL PROTECTED]
 Software Engineerphone: 414-908-1809
 Weyco Group, Inc.  fax: 414-908-1601

 -
 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]



Re: Is there a line continuation character in Velocity?

2005-11-17 Thread Mike Kienenberger
There was talk at one point about allowing multi-line statements, but
I don't know what relesae of velocity (if any) this feature was
scheduled for.

On 11/17/05, Glenn Holmer [EMAIL PROTECTED] wrote:
 On Thursday 17 November 2005 11:33, Mike Kienenberger wrote:
  Well, it's a misnomer to call ## a line continuation character.
  It's a to-end-of-line comment character.
 
  You can't use it to make velocity statements into multiline
  statements. You can only use it to make literal text into multiline
  literal text.

 Oh nuts.  I've an even worse one later in that file... so there's no way
 to make a 257-character line more readable, then?

 --
 
 Glenn Holmer  [EMAIL PROTECTED]
 Software Engineerphone: 414-908-1809
 Weyco Group, Inc.  fax: 414-908-1601

 -
 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]



Re: Newline issues

2005-11-15 Thread Mike Kienenberger
If you end a line with ##, the rest of the line, including the
newline, is discarded from the output.

So you'd do

#macro (getMonths $month)##
#if ($month == 0)##
Jan #elseif($month == 1)##
Feb##

and so on.

On 11/15/05, Heimerl, Kurtis [EMAIL PROTECTED] wrote:
 I have a number of velocity macros that seem to be adding newlines, and i'm 
 wondering if there is any easy way around this problem. The two offending 
 macros are:

 #macro (getMonths $month)
 #if ($month == 0)
 Jan #elseif($month == 1)
 Feb
 #elseif($month == 2)
 Mar
 #elseif($month == 3)
 Apr
 #elseif($month == 4)
 May
 #elseif($month == 5)
 Jun
 #elseif($month == 6)
 Jul
 #elseif($month == 7)
 Aug
 #elseif($month == 8)
 Sept
 #elseif($month == 9)
 Oct
 #elseif($month == 10)
 Nov
 #elseif($month == 11)
 Dec
 #else
 ##nothing
 #end
 #end

 and

 #macro (adjustYear2k $year)##plus 1900, date object returns years since 1900
 #set ($year = $year + 1900)
 $year
 #end

 when put into this block of vm code (ignore the depreciated date object)
 #set ($year = ${popupModel.batchInfo.getBatchStartDate().getYear()})
 #set ($month = ${popupModel.batchInfo.getBatchStartDate().getMonth()})
 #set ($hour = ${popupModel.batchInfo.getBatchStartDate().getHours()})
 #set ($minute = ${popupModel.batchInfo.getBatchStartDate().getMinutes()})
 #set ($temp = #getMonth($month))
 #set ($temp2 = #adjustYear2k($year))
 #set ($temp = ${popupModel.batchInfo.getBatchStartDate().getDate()} ${temp} 
 ${temp2})
 tdUpload Start Datebr/input type=text readonly=readonly 
 value='${temp}'//td

 i get the following html:
 tdUpload Start Datebr/input type=text readonly=readonly value='27 Oct
   2005
 '/

 This causes the 2005 to not be rendered, as it's outside the input object's 
 one line. I need to remove the newlines that are causing the spacing after 
 the macro calls, but i can't seem to find where/how to do this. The extra 
 sets are my feeble attempts to diagnose the issue. I've tried removing all 
 the newlines from the macros, making them single line functions. This didn't 
 work. There has to be an easy way to do this, vtl is a templating language, 
 it's all about data formatting!

 Any help would be appreciated.
 Kurtis



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



Re: Is there a line continuation character in Velocity?

2005-11-10 Thread Mike Kienenberger
Yes, ## comments out the newline and any other trailing text.

On 11/10/05, Jenny Mathew -X (jenmathe - Infosys at Cisco)
[EMAIL PROTECTED] wrote:
 ## seems to provide the line continuation ability. Probably with a  
 prepended so as to ensure that the arguments are separated by white
 space

 #set($command=foo)
 #set($args2=bar)
 #set($args1=bar)
 #set($args3=bar)
 #set($args4=bar)

 $command $args1 ##
 $args2 ##
 $args3 ##
 $args4

 Gives the following output
 foo bar bar bar bar

 -Original Message-
 From: Jenny Mathew -X (jenmathe - Infosys at Cisco)
 Sent: Thursday, November 10, 2005 11:21 AM
 To: Velocity Users List
 Subject: Is there a line continuation character in Velocity?

 Hi,

 I have a situation where some lines in the template script may be quite
 long and for readability purposes we would like to write part of the
 line on the next line but the merged output should be displayed as a
 single line.

 Is there a way to ensure that the same line is stored in the
 StringWriter after the merge process as a single line? In otherwords is
 there a line continuation character in velocity?


 Thanks in advance!
 Jennifer

 -
 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]



Re: Question about ##

2005-11-07 Thread Mike Kienenberger
You need to use this:

#set ($h = '#')

NumberFormat ss:Format=${h},${h}${h}0.0/

To be safe, you should always escape # and $ symbols.

On 11/7/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi everyone, I'm using Velocity for generating Excel file. I save my
 source file in excel xml format. After that, I add the Velocity tag in
 it to be able to parse it. Everything work great eccept the faq that
 Excel save the format of a Cell in the format #,##0.0. So Velocity trap
 that as a comment and wipe the rest of the line.

 The file became a not valid xml after that of course.

 So my question is: Is there a way to tell Velocity to not parse the
 comment ? Or does exist a way to change the comment sing ? If not,
 Someone have a good idea to overcome that issue? I can't espace ## sign
 in the template because Excel will not recognize it after that.


 Here a example of the tag in problem.

 Style ss:ID=s34
Font ss:FontName=Arial Narrow x:Family=Swiss/
NumberFormat ss:Format=#,##0.0/
   /Style

 Sorry for the bad english. I'm french.


 Thanks everyone for your help. Sorry if the question already been ask. I
 search on the archive of the mailing list and found nothing.

 -
 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]



Re: whitespaces, why?

2005-11-04 Thread Mike Kienenberger
Use ## for blank lines.
Use ## at the end of every non-blank line.

This will get rid of all newlines.

For example:

#macro(relation $lrelations $number)##
##
#set($i = 0)##
##
#foreach($rel in $lrelations)##
##
#set($i = $i+1)##
##
#if($number == $i)##
##
$rel##
##
#end## if
##
#end## foreach
##
#end## macro



On 11/4/05, Pascual Queralt [EMAIL PROTECTED] wrote:
 Hi to everyone.

 Well, I am starting with Velocity and I have a problem with the whitespaces 
 that appear when I call a Velocimacro.
 My Velocimacro is the next.

 #*

 * Obtenemos el nombre de la relacion $number

 * que se encuentra en en el conjunto de relations

 *#

 #macro(relation $lrelations $number)

 #set($i = 0)

 #foreach($rel in $lrelations)

 #set($i = $i+1)

 #if($number == $i)

 $rel

 #end

 #end

 #end



 and the sentence that call this velocimacro is the next:

 ##

 ceq ModelGenHidden (#relation($relations 1) ; ? Set{ N, M } ? Model ? 
 TargetMM ?

 ##

 but the result I get in the console is :

 ##

 ceq ModelGenHidden (
 Package2Schema

 ; ? Set{ N, M } ? Model ? TargetMM ? TracMM)



 ##



 Does anybody know how I can prevent this white spaces??

 Many thanks.



  Pascual







 -

 Correo Yahoo!
 Comprueba qué es nuevo, aquí
 http://correo.yahoo.es


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



Re: Best practice for escaping?

2005-10-28 Thread Mike Kienenberger
These two techniques are what I've used to write templates that
generate other velocity templates.   As Ahmed says, it makes the code
hard to read, but there aren't any better options in Velocity yet.

In the Objective C templating engine I used before Velocity, it was
handled by changing the starting and ending delimiters.   Ie, instead
of #{if}, you'd change the delimiters to *if*.

Velocity doesn't currently support changing delimiters (or even
starting/ending delimiters for directives), so you'll have to use
something else if you aren't willing to live with escaping all # and $
symbols.While maintaining such templates is a nightmare, creating
them initially isn't a big deal since you can just do a global find
and replace of both symbols.

On 10/27/05, Nathan Bubna [EMAIL PROTECTED] wrote:
 personally, my recommendation would be to ditch the escaping rules for
 variables and go with the following:

 #set( $D = '$' )
 ${D}myVar

 or you can add the new EscapeTool (in VelocityTools 1.2-rc1) to your
 context and do:

 ${esc.d}myVar

 escaping is really a pain if you aren't sure whether a variable will
 be there or not.  i haven't done it to generate another velocity
 template, but the thought is unpleasant. :)

 On 10/27/05, Ahmed Mohombe [EMAIL PROTECTED] wrote:
  Hi,
 
  Is there a best practice on how to escape a velocity template.
  (so in order to generate another velocity template?).
 
  The escaping rules are clear however it seems a nightmare to me
  to apply them because of the fact that 'undefined' variables are threated
  different by the escape rule.
 
  The problem is that some variables exist both in the source and the target 
  template.
  At the moment I tried so many 'tweakings' and I never get what I expect.
  I'm at the point to use another template engine to generate velocity 
  templates,
  just to avoid the escaping nightmare.
 
  Thanks in advance,
 
  Ahmed.
 
 
  -
  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]



Re: url rewriting in Velocity

2005-10-12 Thread Mike Kienenberger
In Struts with velocity, I did this by creating a subclass of linkTool
that encoded the url and creating a servlet that decoded the url and
forwarded it to my real servlet.My goal wasn't to just encode the
url but to preserve page-scoped values, so it's not a direct match,
but the same ideas should work.   Note that the matching between the
encoded and unencoded urls was stored in the session for each user.

I suppose another way to do it would be to simply encrypt the url and
then you'd just need to store the encryption key in your application.

On 10/12/05, Sreeni Gali [EMAIL PROTECTED] wrote:
 Hi guys,
   How to do url rewriting in Velocity.
  In my velocity page there is an anchor link to another velocity page.
 example has given below

 http://localhost:8080/rgcip/ViewProjectFinancialSummary.vm?tabName=ProjectssearchMessage=Project%20Financialname=FinancialusDotNo1=US123456
  i don't want to expose this name and value pair in the browser . How to do
 URL rewriting in velocity so then i can use that to rewrite my url so the
 person con't understand the url.
  is there any suggestion to do this?
  Thanks advance.
  Regards
 Gali



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



Re: Whitespace and Nitpicking

2005-10-08 Thread Mike Kienenberger
Not all output can be run through a cleaner.
One of the things I use Velocity for is to generate plain-text email.

It requires that I have complete control over line-breaks and output.

A general purpose templating language must have a known methodology
for generating whitespace.   Velocity has one, but it's not
inituitive.

On 10/8/05, Andrew Mason [EMAIL PROTECTED] wrote:

 Can I just make a quick point on the whole whitespace issue. Velocity provides
 you with a couple of ways to handle your  own output. For example using
 String writers etc...I use a really nice set of classes called JTidy for HTML
 output, you can run your output through that and create perfectly tidy HTML
 (and valid if your designer isn't so talented). There is also nothing to stop
 you from writing your own cleaner for other languages where an implementation
 isn't already there. I can understand why people want these features in
 velocity, Yes it would be handy, yes it should be added as enough people want
 it, but I'm not sure it's as critical as many people make it out to be (i
 could be wrong). You are given methods to allow you to run the output through
 what ever classes you want. The only time where this may not work is when
 your doing servlets with the old VelocityServlet (i still don't use
 VelocityViewServlet yet so the option maybe available in that too).


 Andrew

 -
 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]



Re: What's the ideal syntax? Was: [ANN] Viento - WHY?

2005-10-08 Thread Mike Kienenberger
Sure there is.

This is handled by the Objective-C MiscMergeKit template engine by
having all variables and directives enclosed in a starting and ending
tag.

Ie,  #if (x)# text #else# text #endif#

or ${if (x)} text ${else} text ${endif}


The actual starting and ending tags can at any point be changed using a
#delimiters new-left-delimiter new-closing-delimiter # directive.


Ie,

## write html template info

#delimiters {$ $} #

write shell script template info

{$delimiters # # $}

write more html template info

I haven't found it all that useful to switch delimiters in the middle of a
template, but I definitely have found it useful to switch delimiters
at the start of a file.

On 10/8/05, Jason Pettiss [EMAIL PROTECTED] wrote:
 It's an interesting question... I guess it's a tradeoff between syntax
 stability and error robustness.  The former favors smart users who are
 used to dealing with the absolutes imposed by programming languages, the
 latter, artsy-fartsy types who honestly have trouble terminating html
 elements properly.

 JSP for example has absolute delimiters which are glaring (and ugly).
 You get one of those wrong, your whole page breaks fantastically, and
 without a nice error system or checking the logs, you won't know where
 the problem is.  Taglibs just make things worse because in a page that's
 designed to generate HTML they hide really well... and still even one
 mistake and BOOM!  Developers dislike it, artists fear it...

 Velocity needs just a single character most of the time, and it's very
 tolerant of mistakes.  Most of the time it'll spit out a full page and
 the non-technical user can see exactly where they screwed up, and why.
 This makes it very friendly for the user, and intuitive for most
 purposes, but at the expense of having an absolute way to escape and
 delimit... which means sometimes the mechanism breaks down.  Typically
 this is just a minor annoyance to a non-technical user, who most of the
 time doesn't grasp the difference between dynamic and static content
 anyway-- and so is using trial and error, and will do so here, to get
 over the little stumbling blocks imposed by a very liberal syntax.

 Due to the lack of reliable escaping, Velocity would break down entirely
 if the page being generated were, say... oh I dunno... another Velocity
 template!  Fortunately this is highly uncommon and I don't think it's
 the intention of the language.  Velocity also isn't well suited for
 strict content where whitespace and newlines really matter-- like
 certain WML-- but then again, JSP is pretty terrible at this too.  As a
 general purpose template language in a world awash with XML and HTML
 lookalikes, Velocity does well.  If the web were composed of shell
 scripts I am sure it wouldn't be as well accepted.

 I do think there's got to be a way to get the flexibility and liberal
 syntax in the 90% scenario, yet have a way to reliably escape, delimit,
 control whitespace conventions, etc, in the other cases.  Also-- the
 template language I want also lets me choose the syntax markers and
 define them in the content.  Then all I have to do is choose delimiters
 which don't appear that often in the page, and I'm always basking in the
 sunny 90% scenario... ;-)

 About the macro-with-body... that's really just two macros on either
 side of some content, isn't it?  Its nice to not have to remember to
 close, but you have to do that with for loops and if statements and
 comments anyway, right?

 --jason

 Daniel Dekany wrote:

 Friday, October 7, 2005, 11:12:21 PM, Chad Meadows wrote:
 
 
 
 I simply don't quite understand what seems to be a pushback to
 acknowledging there is a community of people who do not like the syntax. I
 have shown the syntax of velocity side by side with freemarker among those
 who had never seen either.  Velocity was preferred.
 
 
 [snip]
 
 DISCLAIMER: This will NOT be a FreeMarker advertisement. Also, I do NOT
 like the FreeMarker syntax (but not because of it usage of cryptic
 delimiters... there other things historically bungled in it), although I
 surely prefer it over Velocity's.
 
 meta-discussion
 The unimportant thing what I want to say is that Jonathan  behaves
 roughly in this case because he becomes angry when he faces exactly the
 same case of, well, apparent lack of professional experience (read:
 ***IGNORANCE!!!***, just I don't wanted to say that :)) again and again
 and again... the syntax stuff. (Plus, he is pissed of on Jakarta people
 in general, so it's not the place where he will try to keep cool his
 blood when it wants to boil.)
 /meta-discussion
 
 
 So, what apparent lack of professional experience do I refer to?
 
 One thing is that evaluating a template language primarily based on the
 first impression look and feel goodness of its syntax is, well... Even
 evaluation a template engine primarily based on it syntax is, well...
 (as far as the syntax is within the borders of sanity, that is). But let
 this alone now 

Re: What's the ideal syntax? Was: [ANN] Viento - WHY?

2005-10-08 Thread Mike Kienenberger
Daniel Dekany wrote:
 No template language can be too good at that... Simply, the basic idea
 of a template languages is incompatible with strict white-space control.

On the contrary, template languages are *IDEAL* for strict white-space
control.  That's the whole template part of template language.  A
template language is a means to specify an exact output format, and
whitespace is part of that.   Even velocity has strict white-space
control.  It just happens to have a non-intuitive implementation.

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



Re: What's the ideal syntax? Was: [ANN] Viento - WHY?

2005-10-08 Thread Mike Kienenberger
On 10/8/05, Jonathan Revusky [EMAIL PROTECTED] wrote:
 Again, the fact that it is possible to achieve precise control of
 whitespace is not the key point. It is that you want such control while
 having a reasonable, human-readable template. That is the raison d'être
 of templates really.

In a word, No.

The reason for having templates is to generate controlled formatted output.

The key point is that control over whitespace is often a necessity. 
 A worthy subgoal might be that the template is easy to read, but
that's just a nice extra, not a key point.

I can live without the templates being easy to read.  I can't live
with uncontrollable formatting.

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



Re: [ANN] Viento

2005-10-08 Thread Mike Kienenberger
And add java and jsp/jsf and javascript.

Probably some others as well.

On 10/8/05, Will Glass-Husain [EMAIL PROTECTED] wrote:
 Hi,

 I really like how JSP 2.0 HTML escapes all references by default.  Makes
 life simpler.  It's only the references that matter anyway.

 In Velocity 1.5 we've added a special ReferenceInsertionHandler that will
 automatically escape all references.  This can be configured in
 velocity.properties with regular expressions, allowing some expressions to
 be escaped and others not.  There's also a choice of HTML, XML, and
 Javascript escaping.  Probably we should add CSS (escape '@' character) and
 URL.

 Best,
 WILL


 - Original Message -
 From: Austin Taylor [EMAIL PROTECTED]
 To: Velocity Users List velocity-user@jakarta.apache.org; Daniel
 Dekany [EMAIL PROTECTED]
 Sent: Saturday, October 08, 2005 7:17 AM
 Subject: Re: [ANN] Viento


  What's if you have } in the static text (CSS, JavaScript)?


 You're rather obligated to escape it. Right now the stop gap is
 $escape('}'). That's going to get old pretty quick. I'm still thinking about
 what to do there.

 Austin


 -
 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]



Re: Clean way to iterate over a distinct set of items?

2005-10-05 Thread Mike Kienenberger
Don't draw unwarranted conclusions.  I never said anything about using
the template as MVC :)

In fact, the context makes available a data model, and I use several
templates to generate various files based on the data in that model.

In this particular case, the task I need to perform should all be done
in the view layer anyway.

John Withers provided an excellent example of using [] to create the
sublist, and when I revisit my templates again, I'll change over to
using that method.  Thanks, John!

On 10/5/05, Daniel Dekany [EMAIL PROTECTED] wrote:
 Monday, October 3, 2005, 10:04:34 PM, Mike Kienenberger wrote:

  Yes, the problem is that I don't have access to the context in this
  situation, only to the template.  I needed a 100% VTL solution since I
  couldn't add anything to the context.

 That's an ugly situation. An MVC template language can't be used alone
 for generating pages. It's only works in pair with the action or
 whatever you call the part that calculates the stuff to display.
 Otherwise the whole point of it, the separation, lost...

 --
 Best regards,
  Daniel Dekany



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



Clean way to iterate over a distinct set of items?

2005-10-03 Thread Mike Kienenberger
I'm looking for a clean way to iterate over a distinct set of items.

As an example. consider

#foreach $employee in $employeeList

where $employee.getDepartment() may or may not return a unique value.

What I really want to iterate over is the unique set of departments in
the employee list.

Ideas?

And this isn't really what I'm trying to do -- the real example is
much more complicated, and there's no easy way to add a tool to the
context so that I could have the equivalent of
$tool.getUniqueDepartmentsForEmployeeList($employeeList).

-Mike

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



Re: Clean way to iterate over a distinct set of items?

2005-10-03 Thread Mike Kienenberger
Yes, the problem is that I don't have access to the context in this
situation, only to the template.  I needed a 100% VTL solution since I
couldn't add anything to the context.

On 10/3/05, Will Glass-Husain [EMAIL PROTECTED] wrote:
 Myself, I usually do this in the controller and pass the unique list to
 Velocity.  More often I have a single object (e.g. $form) and just make a
 method that translates:

 $form.employeeList
 $form.uniqueEmployeeList

 each method drawing from the same original data source.

 WILL

 - Original Message -
 From: Mike Kienenberger [EMAIL PROTECTED]
 To: Velocity Users List velocity-user@jakarta.apache.org
 Sent: Monday, October 03, 2005 12:14 PM
 Subject: Clean way to iterate over a distinct set of items?


 I'm looking for a clean way to iterate over a distinct set of items.

 As an example. consider

 #foreach $employee in $employeeList

 where $employee.getDepartment() may or may not return a unique value.

 What I really want to iterate over is the unique set of departments in
 the employee list.

 Ideas?

 And this isn't really what I'm trying to do -- the real example is
 much more complicated, and there's no easy way to add a tool to the
 context so that I could have the equivalent of
 $tool.getUniqueDepartmentsForEmployeeList($employeeList).

 -Mike

 -
 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]



Re: Clean way to iterate over a distinct set of items?

2005-10-03 Thread Mike Kienenberger
Thanks.  Creating a HashSet was my first thought at well, but I
couldn't remember the syntax, nor under what situations it was allowed
:)

What I have works, and while it's ugly, it's good enough :)   If I'd
seen the newInstance() example first, I would have went with that,
though.

And congrats, Nathan!   Your addition to the core velocity
contributors has been a long time coming!

On 10/3/05, Nathan Bubna [EMAIL PROTECTED] wrote:
 well, since Will's proposed security enhancements haven't yet arrived,
 why not do something like:

 #set( $set = $anything.class.forName('java.util.HashSet').newInstance() )
 #foreach( $thing in $list )##
 $!set.add($thing.subThing)##
 #end
 #foreach( $subThing in $set )
 $subThing
 #end

 :)

 On 10/3/05, Mike Kienenberger [EMAIL PROTECTED] wrote:
  Yes, the problem is that I don't have access to the context in this
  situation, only to the template.  I needed a 100% VTL solution since I
  couldn't add anything to the context.
 
  On 10/3/05, Will Glass-Husain [EMAIL PROTECTED] wrote:
   Myself, I usually do this in the controller and pass the unique list to
   Velocity.  More often I have a single object (e.g. $form) and just make a
   method that translates:
  
   $form.employeeList
   $form.uniqueEmployeeList
  
   each method drawing from the same original data source.
  
   WILL
  
   - Original Message -
   From: Mike Kienenberger [EMAIL PROTECTED]
   To: Velocity Users List velocity-user@jakarta.apache.org
   Sent: Monday, October 03, 2005 12:14 PM
   Subject: Clean way to iterate over a distinct set of items?
  
  
   I'm looking for a clean way to iterate over a distinct set of items.
  
   As an example. consider
  
   #foreach $employee in $employeeList
  
   where $employee.getDepartment() may or may not return a unique value.
  
   What I really want to iterate over is the unique set of departments in
   the employee list.
  
   Ideas?
  
   And this isn't really what I'm trying to do -- the real example is
   much more complicated, and there's no easy way to add a tool to the
   context so that I could have the equivalent of
   $tool.getUniqueDepartmentsForEmployeeList($employeeList).
  
   -Mike
  
   -
   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]



Re: Static calls, and accessing map of maps

2005-09-28 Thread Mike Kienenberger
On 9/28/05, Daniel Brownell [EMAIL PROTECTED] wrote:
 I have 2 questions:  the first, is, can I get from an int to an integer
 in the VTL, as so:

 $Integer.getInteger($String.valueOf($myInt))?

 It just prints all that text back out, so I don't know if it works.

You can't call static methods from Velocity.

You can use NumberTool if you install it into your context:

http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/NumberTool.html

$numbertool.toNumber(0)

Note that $myInt should already be a Number since I don't think you
can store primitive types in velocity.

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



Re: Escaping HTML control characters within velocity?

2005-09-13 Thread Mike Kienenberger
http://wiki.apache.org/jakarta-velocity/EscapeTool

Particularly,

http://svn.apache.org/viewcvs.cgi/jakarta/velocity/tools/trunk/src/java/org/apache/velocity/tools/generic/EscapeTool.java?view=markup


On 9/13/05, Peter Locke [EMAIL PROTECTED] wrote:
 I display some text that may or may not contain html control characters (''
 , '', etc) - if it does contain them, I would like them to be converted to
 their 'safe' representations, such as 'lt;' so that they display and don't
 alter the html .  Is there a way to do this built into velocity?  My initial
 thought was to create my own tool and use something like Spring's
 HtmlUtils.htmlEscape(...), but I don't want to re-invent the wheel if it is
 already possible.  As a side note, performance is critical; This method will
 theoretically be called on text on our main search results page, which has a
 huge number of hits daily, and I want to put as little additional strain on
 our application servers as possible.
 
 Any feedback is appreciated.
 
 --
 Peter Locke
 Senior Engineer / Dev Lead
 www.abebooks.com http://www.abebooks.com/
 
 
 


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



Re: [OT] JSF and Velocity

2005-07-18 Thread Mike Kienenberger
Matthias, do you really see the need for JSF/Velocity support with the
availability of facelets?  I know you took a look at it a few days
ago.

I'm a long-time user of Velocity, and I'd been waiting for a Velocity
rendering kit for some time, but I think facelets is a better fit with
JSF, and provides all the same benefits.  (The Velocity YMTD article
could equally be applied to facelets).

-Mike

On 7/18/05, Nathan Bubna [EMAIL PROTECTED] wrote:
 cool!  i've long been told and known that you could integrate Velocity
 into JSF for rendering.  it's nice to see someone actually dig in and
 try it out.  :)  this sort of thing (if further developed) would
 probably make me much happier about the possibility of moving to JSF
 and building components with it.  JSF seems to be gaining momentum.
 it'd be nice to transfer some of my velocity work/skills to that
 arena.
 
 On 7/7/05, Matthias Wessendorf [EMAIL PROTECTED] wrote:
  Hi guys,
 
  just a short link. Yesterday I played with a first (plain) version of a 
  velocity based renderer
  for JSF UI Components. With renderers like that you are very flexible in 
  changing the *rendering behaivor*
  of the ui components.
 
  see here:
  http://people.apache.org/~matzew/jsfvelocity.html
 
  I'll look deeper into the stuff soon ... ;)
 
  Best regards,
  Matthias
 
  -
  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]



Re: handling -ve currency in $number.format('currency',$myNumber) in velocity templates

2005-06-03 Thread Mike Kienenberger
Kailash Sethy [EMAIL PROTECTED] wrote:
 Hi Mike,
 If I use the  $number.format('currency',$myNumber) for a -ve number,
 the output becomes ($number)
 
 $myNumber - -13.55
 $number.format('currency',$myNumber)-  ( $13.55) 
 
 How to show with -ve sign  without parenthesis bracket after
 formatting?

Your best bet is to ask on the velocity-user@jakarta.apache.org mailing 
list, to which I've cc'd this message.

Internally, NumberTool just references NumberFormat:

http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html 

You can also cheat and treat the result of 
$number.getNumberFormat('number', $number.getLocale())) as a 
DecimalFormat, although this may fail for releases other than Velocity 1.3.1 
and Velocity Tools 1.1.

#macro (formattedCpac $value $valueIfEmpty)

#set ($cpacFormatter = $number.getNumberFormat('number', 
$number.getLocale()))##

${cpacFormatter.setMinimumFractionDigits(5)}##

${cpacFormatter.setMaximumFractionDigits(5)}##

#if($value)${cpacFormatter.format($value)}#else${valueIfEmpty}#end#end


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



Re: [vel-tools] LinkTool and Oracle Application Server

2005-04-16 Thread Mike Kienenberger
Thanks, Shinobu.


On 4/15/05, Shinobu Kawai [EMAIL PROTECTED] wrote:
 Your browser's cookie support might be off.  See Servlet Spec
 SRV.7.1.3 URL Rewriting.

Right, I've already read that.

However, this is a customer's browser, and it tends to happen in the
middle of a session.   It seems unlikely (but not impossible) that
they turned off cookies at that point.

 I'm not sure about this one.  It shouldn't affect the servlet
 behaviour.  Maybe an OAS problem?
 ## I've had troubles with OAS in the past, too.  Like sessions not 
 supported...

Yeah, I'm starting to wonder if OAS uses  URL?parameters;jsessionid=
rather than
URL;jsessionid=?parameters.

Unfortunately the Servlet Spec is silent on the ordering when it
includes parameters.

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



[vel-tools] LinkTool and Oracle Application Server

2005-04-15 Thread Mike Kienenberger
Every once in a great while, I end up with LinkTool generating a URL like

/myApp/ViewBillForAccount.do;jsessionid=0afefe11ce615ccf0fdd87a74668c2c9ab6bc8595b0.nk9Dp6Lvr70LnMTBrAjv-
AbJphCNaN0Mcybtah0IaxiO-
x8Pb2SLbMTyc315wnhaInAjymxbwmhqRcgSHc30Ka2bzmAzGp65Kq35B-
AjwokLGml1KakqInRnbmgTxpQOxax4Lax8MbN0Q8Oexfk9Kq2bynknqrkLOlQzNp65In0__?account=0

instead of

/myApp/ViewBillForAccount.do?account=0

which causes this code

String anAccountIndexValueString = 
(String)request.getParameter(account);


to return null instead of 0.

Has anyone else seen this behavior?

Thanks,

-Mike

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



Re: How to convert string in int

2005-03-23 Thread Mike Kienenberger
tarun Narang [EMAIL PROTECTED] wrote:
 Can anyone tell me that how the string can be converted into  int in VTL
 I am recieving the value in count variable through getRequest but this
 variable has a string value and i have to add some int value in this count
 variable like $count + 5.
   #set ($count = $!data.getRequest().getParameter(countRow))

It's only necessary to ask a question once, by the way.

I'd perform this conversion using the NumberTool.

ie, once you have $numberTool installed in your context,

$numberTool.toNumber($count)  -- The result of this operation will be of 
class Number


http://jakarta.apache.org/velocity/tools/generic/
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/NumberTool.html

Note that tools like NumberTool are just plain old java objects, and you can 
put them into your context in many ways, the easiest of which is.

context.put(numberTool, new 
org.apache.velocity.tools.generic.NumberTool());

-Mike

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



Re: reading an array's length?

2005-03-18 Thread Mike Kienenberger
Christofer 'boz' Jennings [EMAIL PROTECTED] wrote:
 Is there a binary for ArrayTool somewhere or do I just build it?
 
 And how would it get configured programmatically (eg. 
 velocity.setProperty())?

It's included with the latest (cvs) Velocity tools, I think.

It's also available on the Velocity Wiki.

http://wiki.apache.org/jakarta-velocity/ArrayTool

It's easy enough to just add it to your project as another java file (that's 
what I'd do).

To use it, either configure it via toolbox.xml (if you're using that) or 
just do a velocityContext.put(arrayTool, new ArrayTool());

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



Re: reading an array's length?

2005-03-18 Thread Mike Kienenberger
Christofer 'boz' Jennings [EMAIL PROTECTED] wrote:
 Ahh. Now I get tools So simple :-)

Yeah, that's exactly how I felt.  It just took me a lot longer to figure it 
out.

Wonderfully brilliant yet simple idea once you realize that there's nothing 
special about a tool.   :)

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



Re: XSLT + Velocity

2005-03-16 Thread Mike Kienenberger
Gopalakrishnan T [EMAIL PROTECTED] wrote:
 Is it possible to create dynamic Velocity pages using XSLT + XML 
combination
 We are creating Velcoity pages dynamically by getting the form 
fields(Textbox,Combobox etc.) from a XML file. Is it possible to have a XSLT 
file for each velocity page and create the form fields dynamically on the 
fly.

Velocity is a server-side technology.  You can do whatever you like with the 
data generated by Velocity once it's on the client side.  You can use 
Velocity to generate html, frames, javascript, XForms, xml, stylesheets, 
whatever.  If that's what you're talking about, then the questions you're 
asking are not directly relevant to Velocity, but are instead questions 
about using your web application framework properly to organize things, 
whatever web app framework that may be.

Now if you're talking about transforming xml data into Velocity templates, 
my question would be Why?   Why not just transform those xml templates 
directly into your final output (html, etc)?   Does it really make sense to 
transform a template (xslt) into another template (velocity), then translate 
that template into your final output (html)?  What are you hoping to gain?

[Note that my experience with XSLT is extremely limited, so maybe I'm 
attributing more power to it than it actually has.]

-Mike

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



Re: velocity tools init

2005-03-15 Thread Mike Kienenberger
Charles N. Harvey III [EMAIL PROTECTED] wrote:
 Quick question about some of the Velocity Tools.  How come the Struts
 Tools and View Tools implement ViewTool and have an init() method
 but the generic tools do not?  How do they actually get initialized?
 Do I have to just do new DateTool() and it works?  It seems like it, but
 I just wanted to double check.

Yep.  Tools are plain old java objects.

The view tools have to be init'd because they need to be set up with 
references to the servlet.

-Mike

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



Re: Extra space appearing in the if /else block

2005-03-12 Thread Mike Kienenberger
Gagan 007 [EMAIL PROTECTED] wrote:
 #if ($obj.isPreviousEmployee())Yes #else NO 
  
 if the value of isPreviousEmployee() is true then it works ok(it displays 
Yes) 
 if the values of isPreviousEmployee is false then is displays NO (extra 
space before NO Appears)
 as there is a space between #else and NO (we cannot write #elseNO in the 
template)

#if ($obj.isPreviousEmployee())Yes#else#**#NO

#* this is a velocity inline comment, good for removing spaces after 
#directives *#
## this is a velocity to-end-of-line comment, good for removing newlines

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



Re: Escaping in VTL (was Re: Velocity JSP Generation)

2005-02-25 Thread Mike Kienenberger
Will Glass-Husain [EMAIL PROTECTED] wrote:
 Doesn't quite work that easily.
 
 The problem is that if #directive is not an actual macro, than 
\#directive 
 is shown verbatim.  You only should escape when the same  code is legit in 

 both the source and the generated Velocity.  This can be a little 
confusing.

Now, see, that's exactly the kind of garbage I avoid.  I see now I left off 
another rule that I follow.

- Always perform escaping with variable replace (preferrably EscapeTool).

Ie, ${esc.hash} or ${poundSign} and not \#

-Mike


 - Original Message - 
 From: Mike Kienenberger [EMAIL PROTECTED]
 To: Shinobu Kawai [EMAIL PROTECTED]; Velocity Users List 
 velocity-user@jakarta.apache.org
 Cc: Velocity Users List velocity-user@jakarta.apache.org
 Sent: Thursday, February 24, 2005 7:07 PM
 Subject: Re: Escaping in VTL (was Re: Velocity JSP Generation)
 
 
  Shinobu Kawai [EMAIL PROTECTED] wrote:
   Escaping the VTL properly was a little challenging, but otherwise it 
   was
  no
   big deal.
 
  I still don't get the whole escaping scheme, partly because I can't
  find any documentation that is completely correct.  We might want a
  document totally devoted to escaping in VTL.  :(
 
  Escape all [$], [#], [], [!] and ['].  (actually, ! might be overkill, 
  but
  better safe than sorry.) Just use your tool :)
 
  Always use formal notation ${x}
 
  That's always worked for me, and never surprises me.
 
  -Mike
 
  -
  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]



Re: Velocity JSP Generation

2005-02-24 Thread Mike Kienenberger
Florin Vancea [EMAIL PROTECTED] wrote:
 But really, what if (only what if) one would provide the Struts validator
 and config files (which are info-rich-enough), along with the *.properties
 containing messages, and at the startup of the WAR (or even at build time)
 Velocity would generate a set of Velocity templates for all required pages
 (maybe even Action classes).

I take a Cayenne database model, run it through Velocity and create a 
combination of nine struts-config files, validator xml files, java actions, 
and velocity templates for generating reports on database entities and 
creating/editing database entities.  Cayenne takes the same database model, 
runs it through velocity and creates database layer objects.   I just give 
my ant task a database table entity and out comes a report component and 
editing tool.  The only thing I might do afterward is swap a few fields on 
the html.vm template to organize the form differently.  That and update my 
main struts-config.xml file to include all of the new pieces.

So it's certainly doable.

-Mike

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



Re: Escaping in VTL (was Re: Velocity JSP Generation)

2005-02-24 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
  Escaping the VTL properly was a little challenging, but otherwise it was 
no
  big deal.
 
 I still don't get the whole escaping scheme, partly because I can't
 find any documentation that is completely correct.  We might want a
 document totally devoted to escaping in VTL.  :(

Escape all [$], [#], [], [!] and ['].  (actually, ! might be overkill, but 
better safe than sorry.) Just use your tool :)

Always use formal notation ${x}

That's always worked for me, and never surprises me.

-Mike

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



Re: VelocityViewServlet Differences with VelocityServlet

2005-02-11 Thread Mike Kienenberger
Steve O'Hara [EMAIL PROTECTED] wrote:
 I was invalidating the session when the user sends a logout request.  It's 
a
 bit belt and braces but it insures that the session is destroyed and gets
 the user back to known state i.e. as though they were first visiting the
 site.

I've been doing the same thing with Velocity 1.3.1 and Struts 1.1 for more 
than a year, and I haven't had this problem.

My logout vm file doesn't have any unresolvable references or references 
that would cause it to need to search the session or servlet context.

Steve, my suggestion is also to clean up your template (either by removing 
those references from the template, or copying your servlet context 
attributes into your request attributes in your logout action), or fix the 
code in ChainedContext.getAttribute() to skip over invalidated sessions.  I 
don't think there's a lot of benefit to creating a more convoluted 
workaround that still fails to read attributes from the servlet context when 
it's easy enough to fix the problem directly in Velocity Tools.

Unfortunately, the morons who came up with the HttpSession interface didn't 
bother to provide an isInvalidated() method.

I've been hit by this problem before when iterating through sessions, and 
the best you can do is this:

try

{

o = session.getAttribute(key);

}

catch (IllegalStateException e)

{

// Handle invalidated session state
// o = null; // only here to show how it's 
handled -- should already be 
null

}


Sorry, Nathan, but that's really the only option for dealing with 
invalidated sessions.  You can at least localize the error trapping to the 
one line, though.  [And that's the patch -- replace line 194 in 
org.apache.velocity.tools.view.context.ChainedContext.java,v 1.6 from 
VelTools 1.1 final]

-Mike


 -Original Message-
 From: Nathan Bubna [mailto:[EMAIL PROTECTED]
 Sent: 11 February 2005 01:18
 To: [EMAIL PROTECTED]
 Cc: Velocity Users List
 Subject: Re: VelocityViewServlet Differences with VelocityServlet
 
 
 On Fri, 11 Feb 2005 01:09:10 -, Steve O'Hara
 [EMAIL PROTECTED] wrote:
  Hi Nate,
 
  Thanks for your explanation, it makes sense, but it does raise a couple 
of
  questions.
 
  a) It sounds as though the search for any Velocity variables that are 
not
  defined in a template will cause this error i.e. #if ($blahblah). Surely
  this is a problem in most apps where they are checking for the existence
 of
  a variable?
 
 no.  this is only a problem when a invalidated session object exists
 and Velocity is looking for an undefined variable (or one defined only
 in the servlet context attributes).  most of the time in most apps,
 the session object either doesn't exist or is still valid.  otherwise,
 this would have popped up long ago. :)
 
  b) Your explanation points to a performance degradation over the 
original
  VelocityServlet - is this, or could it be, significant?
 
 doubtful.  when it comes to finding reference values, the only
 degradation in direct comparison to the VelocityServlet should be when
 looking for references that are undefined.  if the app is designed
 ideally, this should rarely happen, and even when it does, the extra
 cost of looking up values further down the chain is quite negligible
 in comparison to the rest of what's happening during the processing of
 a servlet request and rendering of a template.
 
  I've coded round the problem by only invalidating the session in the
  requestCleanup method.
 
 so you're doing the session invalidation during the processing of the
 view?  hmm.  ok, if that works best for you, but just so you know,
 that's not very MVC.  :)  and out of curiousity, where were you doing
 that before?
 
  Steve
 
  -Original Message-
  From: Nathan Bubna [mailto:[EMAIL PROTECTED]
  Sent: 10 February 2005 18:56
  To: [EMAIL PROTECTED]
  Subject: Re: VelocityViewServlet Differences with VelocityServlet
 
  the quick answer to your question (re: differences between the
  servlets) is that the VelocityViewServlet uses a chained context.  the
  ChainedContext looks for references in the toolbox, current (normal)
  context, request attributes, session attributes, and servlet context
  attributes.  when looking for a reference in a template, it searches
  those in that order until the matching key is found.
 
  so the problem is, that in the template being rendered at the end of
  the request which is invalidating the session, there is a reference
  within the block of an #if statement that is not being found in the
  toolbox, normal context, or request attributes.  so, the
  ChainedContext being used by the VelocityViewServlet continues on to
  check the session attributes for that reference.  of course, it's
  smart enough to make sure the session isn't null before trying that,
  but it doesn't have a way to check if the session is valid or not.
  so, 

Re: Immutable pojos as context objects

2005-02-11 Thread Mike Kienenberger
Serge Knystautas [EMAIL PROTECTED] wrote:
 I was wondering if there is a convenient way to restrict method calls on 
 objects I put into VelocityContext.  I use Velocity templates to do 
 dynamic renders high-traffic websites, and I instantiate VelocityEngine 
 objects along with various POJOs that Spring assembles.  These POJOs are 
 sort of like macros and/or scripting support, have been configured with 
 setter-injection, and are exposed to templates using a VelocityContext 
 object.
 
 My problem is that I intend to reuse these VelocityEngine and POJOs 
 across multiple requests, so I do not want to allow template authors to 
 call setter methods and effectively reconfigure the POJOs.
 
 Is there an easy way to either have Velocity prevent certain method 
 calls on context objects, 

Well, the easy answer to this part of the question is to implement a custom 
Uberspect.

http://jakarta.apache.org/velocity/api/org/apache/velocity/util/introspection/Uberspect.html

There's examples of this on the wiki:

http://wiki.apache.org/jakarta-velocity/MultiUberspect
http://wiki.apache.org/jakarta-velocity/LuceneDocumentUberspect

 or otherwise a way to make these POJOs immutable?

Outside of the scope of velocity, but really the heart of the problem even 
with a custom Uberspect.
At some point you either need to enumerate all objects you want to be 
immutable (or mutable), or you need to only stick immutable objects into the 
context.   Personally, I think the second method is easier and safer.

Why don't you stick your POJOs into the template as a wrapper object 
(delegate), with only the getter methods exposed?

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



Re: Immutable pojos as context objects

2005-02-11 Thread Mike Kienenberger
Serge Knystautas [EMAIL PROTECTED] wrote:
 Mike Kienenberger wrote:
  Well, the easy answer to this part of the question is to implement a 
custom 
  Uberspect.
  
  
http://jakarta.apache.org/velocity/api/org/apache/velocity/util/introspection/Uberspect.html
  
  There's examples of this on the wiki:
  
  http://wiki.apache.org/jakarta-velocity/MultiUberspect
  http://wiki.apache.org/jakarta-velocity/LuceneDocumentUberspect

 I was looking to extend VelocityContext to add a putImmutable(key, 
 object) method.  This would create an AOP-style proxy object that will 
 fail on any set method but otherwise just hand calls to the underlying 
 POJO.  Probably something CGLIB could do for me.

Yeah, that's something you could do with an Uberspect.
Set up something so you can do Uberspect.putImmutable(context, key, object) 
which will add it to the context, and add it to a list of objects to which 
you disallow set method calls.

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



Re: Restrict access to Velocity's capabilities

2005-02-07 Thread Mike Kienenberger
Ben [EMAIL PROTECTED] wrote:
 Hi
 
 I have been using Velocity throughout my site and I am in awe with its
 capabilities. However there are situations where I need to restrict
 its capabilities to a certain extend.
 
 For example, my site allows users to upload templates and be able to
 use a number of predefined variables. What I don't want them to do is
 to use Velocity to abuse the system, such as using directives and
 writing macros.
 
 Is there a way to create a Velocity instance with directives and other
 features disabled? The only thing I need is reference to variables.

The best thing to do is simply escape all # symbols when it's uploaded.   
Ie, replace them with $esc.hash or something equivalent.

Personally, I'd go a step further and escape all $ symbols as well, then 
manually unescape any instance of ${esc.dollar}allowed_variable_name back to 
${allowed_variable_name} where allowed variable name is in a preset list.

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



Re: Email VM DateTool Usage Problem

2005-01-22 Thread Mike Kienenberger
John Mahan [EMAIL PROTECTED] wrote:
 I would appreciate some insight into how one tells the Velociy instance to
 import java.util.date and/or the DateTool.
 
 I'm using the following Velocity code that works OK in  my main instance 
but
 will not render in the Email instance:
 
 $date.format('E, d  ',$!FormatItem.newDate)

The easiest way is to use:

context.put(date, new DateTool());



Another way is to use Edgar Poce's standalone toolbox loader posted to the 
velocity-dev list (search or browse the velocity mail archives) or write 
your own toolbox loader:

Date: Fri, 10 Dec 2004 18:13:07 -0300
From: Edgar Poce [EMAIL PROTECTED]
Subject: Re: standalone toolbox loader
To: Velocity Developers List velocity-dev@jakarta.apache.org
Reply-to: Velocity Developers List velocity-dev@jakarta.apache.org
Message-id: [EMAIL PROTECTED]

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



Re: Email VM DateTool Usage Problem

2005-01-20 Thread Mike Kienenberger
John Mahan [EMAIL PROTECTED] wrote:
 I'm using a standalone class to  instantiate a Velocity engine that allows 
 context.puts() into Velocity templates to format Email content.. which 
works OK except the DateTool does not format dates. I suspect this is caused 
because I'm not properly importing the DateTool or setting the right 
Velocity properties when the Email Velocity instance is invoked.

I don't know of anything you've mentioned that would stop it from working.  
DateTool is a plain old java object.  Perhaps you could post the relevent 
java code for setting up the context and the velocity code where you're 
using the DateTool.

-Mike

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



Re: Usage question.

2005-01-17 Thread Mike Kienenberger
Andrew Wilson [EMAIL PROTECTED] wrote:
 Id like to include the following code in my Velocity Template:
 
 ${request.getProperty(Request.ID)}
 
 Unfortunately, this doesn't compile.
 
 Is there a clever way I can do this with a Macro?
 Since request is an instance of Request I would also be happy with
 
 ${request.getProperty(${request.ID})}

If Request.ID is a literal, put it in quotes.
If it's not a literal, you'll have to provide us with more information.

-Mike

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



Re: Chop output...

2005-01-14 Thread Mike Kienenberger
Dimitrios Kolovos [EMAIL PROTECTED] wrote:
 When iterating a collection/array it is usual that you add something after 

 each iteration except for the last.
 
 #foreach ($i in [1..10])$i,#end
 
 produces
 
 1,2,3..10,
 
 The only way I know in which I can omit the last comma is to use 
 velocityount. Nevertheless, I think it would be more elegant if there was 
a 
 variable (e.g. $output) in the context that represented the so far 
produced 
 text.

Most of us just use an #if statement and only output the comma on non-first 
elements.  Here's one way to do it off the top of my head -- could be syntax 
errors.  Some of the ##s are probably overkill, but better safe than sorry.  
Or you could cram it all on one line.

#set( $tempFirstOne = true )##
#foreach ($i in [1..10])##
#if ($tempFirstOne = true)##
#set( $tempFirstOne = false )##
#else## not $tempFirstOne
,##
#end###if ($tempFirstOne = true)
$i##
#end##foreach ($i in [1..10])

-Mike

And as long as we're talking about #foreach#else#end, how about

#onFirst?
#onLast?
#onEmpty?

  :-)

Not unreasonable in a templating language, and definitely more readable than 
the above.

-Mike

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



Re: Question on using text from resource bundles

2005-01-13 Thread Mike Kienenberger
Chris Bailey [EMAIL PROTECTED] wrote:
 I¹m relatively new to Velocity and have one issue I¹m trying to find out
 more info on.  I¹m using Velocity for a web app, and one that will be
 localized in many languages.  So, for my web pages (which are all done via
 Velocity), I¹d like to retrieve text via a resource bundle, and further, 
to
 have some of the abilities provided by MessageFormat.  Essentially, I¹m
 looking for something similar to the ³fmt² JSTL tags (³fmt:message² and 
its
 subtag ³fmt:param²).
 
 Or, a better question might be, what would the ³best practices² be for
 Velocity in this regard?  How are people doing this type of thing when 
using
 Velocity?  It seems reasonable to put this in your view/Velocity markup, 
as
 it¹s view/presentation specific, but I haven¹t been able to find any
 information on this kind of thing.

I use Struts and velocity.   Struts contains a MessageResource class to 
handle this, and Velocity makes it available via the Struts tools.

I believe that the MessageResource classes have now been made into a 
separate Apache Commons MessageResources class, and that might be something 
for you to look into.

Or you could just write your own custom velocity tool (perhaps using the 
struts one as a basis) if that's not a good fit.   A velocity tool is just a 
java class that's stuck into the Velocity context so you can call methods on 
it.

-Mike

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



Re: Context availability during method invocation / ReferenceInsertionEventHandler

2005-01-06 Thread Mike Kienenberger
Vincent van Beveren [EMAIL PROTECTED] wrote:
 I would like to simplify the 
 following piece Velocity code:
 
 $locale = ... user defined locale ...  // this is done while setting 
 up the context
 
 Description: $product.description.toString($locale)
 Title: $product.title.toString($locale)
 
 In which the class product has a method 'getDescription' which returens 
 a home-made object of the class LocaleData. LocaleData is basically a 
 map with as key a locale and as value an object, usually a string. 
 Somewhat like a ResourceBundle (but not quite)
 
 The simplified version would be like this.
 
 $locale = ... user defined locale ...// this is done while setting up 
 the context
 
 Description: $product.description
 Title: $product.title
 
 Anyone has any idea how to accompish automatic parsing of localized data?

What about setting up a localizer velocity tool helper class that handles 
this for you?

] $localizer = ... helper tool with user defined locale ...// this is done 
while setting up the context
] 
] Description: $localizer.get($product.description)
] Title: $localizer.get($product.title)

Or if you wanted to get the localization completely out of the template, use

] Description: $product.localeDescription
] Title: $product.localeTitle

and have those two methods directly call the localizer helper class.


Note that this is actually a question about the use of velocity and not the 
development of velocity, so I've changed the destination mailing list from 
velocity-dev@jakarta.apache.org to velocity-user@jakarta.apache.org

-Mike

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



[Vel-Tools] Converting a long return type into a formatted Date

2005-01-06 Thread Mike Kienenberger
I'm trying to figure out how to convert File.lastModified (type long) into a 
formatted date in Velocity.

It appears that I need to use DateTool.toDate(Long obj) to go from a long 
value to a Date.

However, neither NumberTool nor MathTool provides a method to convert a long 
to a Long.   I can convert it to an Integer with MathTool.toInteger().  Or 
MathTool.toNumber() and -- if the number is large enough -- it'll force it 
to be a Long, but it's not guaranteed.

Perhaps DateTool should be modified to handle toDate(Number obj).   Or 
MathTool modified to provide toLong(), toFloat(), etc.   Or both.

Hopefully, I'm overlooking something obvious, which is why I posted to user 
and not dev.

Thanks,

-Mike

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



Re: [Vel-Tools] Converting a long return type into a formatted Date

2005-01-06 Thread Mike Kienenberger
Nathan Bubna [EMAIL PROTECTED] wrote:
 in VTL, long and Long are the same.  have you tried just using
 DateTool.toDate(Long) with the long?

Just tried it, and it works fine.

I didn't realize that primitive types would convert like that inside nested 
method calls.  I figured (wrongly) that primitive-to-object conversions 
would only take place on the outer-most call when the value was actually 
rendered.

Thanks!

-Mike

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



Re: menus, header, footer, etc with velocity

2005-01-05 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
  I'd like to generate some web pages containing menus, header, footer, 
etc...
  Can someone give me some clues (good practices, pointers) to properly
  organize
  this with velocity.
 
 Take a look at VelocityLayoutServlet and TilesTool.

http://jakarta.apache.org/velocity/tools/view/index.html#VelocityLayoutServlet
http://jakarta.apache.org/velocity/tools/struts/TilesTool.html

I recommend VelocityLayoutServlet over Tiles.  Here's a couple of 
previously-posted examples.  (Weird that the one is only available from 
google cache.)

[Google search for velocity kienenberger header footer -- you probably 
just left off the kienenberger search term :)  ]

http://www.mail-archive.com/velocity-user@jakarta.apache.org/msg13821.html

http://64.233.161.104/search?q=cache:aLlyisxTJzYJ:www.mail-
archive.com/velocity-
user%40jakarta.apache.org/msg12074.html+velocity+kienenberger+header+footerhl=enclient=firefox-
a

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



Re: Disable direct acces to vm's when using velocity + struts + tiles

2005-01-03 Thread Mike Kienenberger
Matt Higgins [EMAIL PROTECTED] wrote:
 Is it possible to disable direct access to vm files ? When using
 velocity and tiles, the user never sees the .vm but if you know the
 correct url you could access 
 
 /myapp/pages/foo/template.vm
 
 This would render a bogus pages as it did not go through the tiles
 processor or any of my struts actions. 

I think that anything you put into WEB-INF is no longer directly accessible.

My velocity templates are in ./WEB-INF/pages and other such subdirectories.

-Mike

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



Re: adding vm file to existing Struts based Application

2004-12-31 Thread Mike Kienenberger
Anaparthi Subrahmanyam [EMAIL PROTECTED] wrote:
 I have one application based on struts framework.I want to adda velocity 
 file after few web pages in the application ,which will add few parameters 

 to the session.
 
 Can anyone help me out the process to do so.
 
 I have just written the html file having form with few pararmeters  
renamed 
 to vm. BUt how to add it to struts framework otherwise i think struts will 

 not able to read the data.

This is just a matter of setting up a standard struts action form and bean.

There's nothing really velocity-related to the process, unless you get fancy 
and pre-populate the form fields.  Just make sure you've installed 
velocity-tools for doing struts form support.


-Mike


Example HTML.vm code:
==
form method=POST action=$link.setAction('ChangeLoggingLevel')

input type=text name=logLevel 
value=$loggingLevelForm.logLevel 
size=40 maxlength=128 /

input type=submit name=ChangeLoggingLevelButton 
value=Change Logging 
Level /

/form

==

Example struts-config.xml code:

==
form-bean

name=loggingLevelForm

type=org.apache.struts.validator.DynaValidatorForm

form-property

name=logLevel

type=java.lang.String/

/form-bean


action path=/LoggingLevels


type=com.xyz.struts.actions.AdministrativeTasks.InitializeLoggingLevelsAction

scope=request

name=loggingLevelForm

validate=false

forward name=Success 
path=/vm/LoggingLevels.do/

/action 

 

 action path=/ChangeLoggingLevel


type=com.xyz.struts.actions.AdministrativeTasks.ChangeLoggingLevelAction

scope=request

name=loggingLevelForm

validate=true

input=/vm/LoggingLevels.do

forward name=Success path=/LoggingLevels.do/

forward name=Failure path=/vm/LoggingLevels.do/   
 

/action 

==

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



Editing wiki pages [was: Re: unwanted whitespace]

2004-12-08 Thread Mike Kienenberger
Rob Butler [EMAIL PROTECTED] wrote:
 I tried to edit the page you suggested, but it said I
 am not allowed to edit that page, and the bottom of
 the page says Immutable page.  Do I need to login or
 something?

Click on UserPreferences in the top upper-right corner.
Once you've created an account, you'll be able to edit pages.

-Mike

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



EscapeTool (and velocity-tool best practices)

2004-12-08 Thread Mike Kienenberger
I started using EscapeTool today (since it was far more comprehensive that my 
primitive and misnamed URLEncoder tool), and noticed that it only took 
String arguments.

So if I had did $esc.html($value) and value wasn't a String, I got 
'$esc.html($value)' returned as a literal.

In general, should Velocity tools that operate on a String operate on an 
Object instead and perform a object.toString() conversion first?  Or at 
least provide Object argument wrapper methods to call the String argument 
methods?

Obviously, I can easily subclass EscapeTool even if no one else agrees with 
me and add public String html(Object object)-like methods, but I'm curious 
what we consider to be best-practices

-Mike


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



Re: EscapeTool (and velocity-tool best practices)

2004-12-08 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
 Just be sure to check for null.

Too late!  I didn't, and already got caught by that error and subsequently 
corrected it. :)


 Overloading in Tools currently gives strange behaviour.

I haven't run into this problem.   Maybe it's because the methods are in two 
separate classes.

When you update your class, you could avoid the problem by only having 
Object argument methods.   The overhead of calling String.toString() should 
be minimal :)

-Mike


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



Re: Velocity tools

2004-12-08 Thread Mike Kienenberger
   What's the best practice for adding a Velocity Tool to the context in
  a standalone app?
  is it manually with something like context.put(tool, new *Tool()) or
  there's a configuration setting I'm missing?

Shinobu Kawai [EMAIL PROTECTED] wrote:
 I guess that's the normal method.  Or, you can use the toolbox
 strategy like VelocityViewServlet and DVSL.
 ## It's not built into Velocity, so you'll have to implement if
 yourself, though.

If you came up with a standalone toolbox loader using the same format as 
toolbox.xml and posted it, it might end up in the next version of velocity 
tools :)

XMLToolboxManager probably does most if not all of what you need already.

-Mike

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



Re: Tiles definitions without tiles-defs.xml

2004-12-06 Thread Mike Kienenberger
Anthony E. Carlos [EMAIL PROTECTED] wrote:
 Thanks so much for the response. I'll look into how Tiles works on the 
 jsp side and see if it can be duplicated in Velocity. I consider myself 
 an intermediate level guy, so I don't know if my patches would be worth 
 anything.
 
 The problem I'm trying to overcome is that I have content creators (not 
 web programmers) who need to be able to create pages. I'd like them to 
 use Tiles because I'm (I'm the programmer) using Tiles and if I update 
 a Tile, it would be great for the whole site to be updated. The problem 
 is that I want to avoid having content creators touch tiles-defs.xml or 
 struts-config.xml, or have to reload/restart Tomcat.
 
 In Struts in Action, page 329, Husted writes that the body-wrap 
 deployment for Tiles is appropriate to avoid creating an extra tile. 
 His example uses insert and put tags to create the definition on the 
 fly. Since this doesn't currently work with Velocity, I'm using 
 Velocity's #parse() directive to simulate some of the tiles stuff. It's 
 a little bit messy, but I think it will work.

Have you considered just using the VelocityLayoutServlet and dumping tiles?

I started my project a year ago using Tiles, but quickly switched over to 
using VelocityLayoutServlet and haven't regretted it.
Our web designer has been able to easily do everything he wants with VLS.   
I'd be curious to know what functionality you'd lose by doing this.

We use something that boils down to the following as our layout template,

html

head

/head


body

#parse($header)


#parse($leftSideMenu)



#parse($body)



#parse($footer)

/body

html



We use a version of Ted Husted's ViewAction class which just takes struts 
parameters and puts them into the velocity context (very trivial class).  I 
can't remember if it's included (or just mentioned) in Struts In Action, 
but I can put it up on the Wiki if it's not already there.

I do let my web designer manage a struts-config-presentation.xml file, but 
he only makes minor changes in it.
An example entry is as follows.  He generally just updates the title parts.  
Anything that's not specifically defined uses the global defaults specified 
at the top of the config file.

action path=/vm/Logout

 type=us_ok_deq_wqdata.http.ViewAction

 validate=false

 
parameter=IsExternal;ShouldShowReturnToLastPageLink;Title;leftSideMenu;loginPanel;header;body;footer;bartitle


   forward name=Title path=Logged out GV E-Bill /

   forward name=bartitle path=Logged out GV E-Bill /

   forward name=body path=/WEB-INF/pages/Logout.vm /

/action


-Mike


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



Re: [FAQ] How do you check for null?

2004-12-03 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
 Problem: I want to check for null, something like this:
 #if ($car.fuel == null)
 
 
 Approach 1: Use the fact that null is evaluated as a false conditional.
   cf. http://jakarta.apache.org/velocity/user-guide.html#Conditionals
 #if( ! $car.fuel )
 
 Note : The conditional will also pass if the result of $car.fuel is
 the boolean false.  What this approach is actually checking is whether the
 reference is null or false.
 
 
 Approach 2: Use the fact that null is quiet references.
   cf. 
http://jakarta.apache.org/velocity/user-guide.html#Quiet%20Reference%20Notation
 #if( $!car.fuel ==  )
 
 Note : The conditional will also pass if the result of $car.fuel is a
 blank String.  What this approach is actually checking is whether the 
reference
 is null or blank.
 BTW, just checking for blank can be achieved by:
 #if( $car.fuel ==  )

So you really either need to use the tool or do this:

#if ((! $car.fuel)  ($!car.fuel == ))

-Mike


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



Re: [FAQ] How do you check for null?

2004-12-03 Thread Mike Kienenberger
Simon Christian [EMAIL PROTECTED] wrote:
 Mike Kienenberger wrote:
  So you really either need to use the tool or do this:
  
  #if ((! $car.fuel)  ($!car.fuel == ))
  
  -Mike
  
 
 No the first bit isn't necessary, just #if( $!car.fuel ==  ) covers 
 the eventualities when testing for null.

That's not true.

car.fuel =  is not the same as car.fuel = null, yet both pass the 
condition.

Unless the template designer knows the underlying type of the java object, 
the only safe solution is to check for (null or false) and (null or 
empty-string) = if true, must be null.

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



Re: XML and velocity

2004-12-02 Thread Mike Kienenberger
Subbiah Raman [EMAIL PROTECTED] wrote:
 I am trying to use a SAX parser in Velocity context and I need to do the 
 following
 
 #set($temp = $root.getRootElement().getChild(email).getText() )
 
 But it throws
 org.apache.velocity.exception.ParseErrorException: Encountered email

In addition to what others have said, you can also use single-quotes inside 
your double-quotes.

#set($temp = $root.getRootElement().getChild('email').getText() )

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



Re: vm to return a binary file

2004-11-25 Thread Mike Kienenberger
Ilan Azbel [EMAIL PROTECTED] wrote:
 I would like a vm to return a binary file and thereby instruct the browser
 not to display it, but rather to download it. That is, ask the user if 
they
 would like to Open or Save the file.
 
 I would like to do this without any redirecting statements - so as soon as 
a
 user requests a certain .vm file, the corresponding java creates some type
 of binary data, and the browser immediately asks whether to open or save
 this data.

Ilan,

Both your requests to create a csv and a binary file for download are 
generally outside of the scope of velocity servlets.

You'd generally do this using a different servlet.

What servlet framework are you using?

For example, in struts, you'd do something like this in an action to create 
a pdf file to download.
To create another file type (cvs, binary), you'd simply change the content 
type and provide a different file generator.

response.setContentType(application/pdf);

ByteArrayOutputStream memoryOutputStream = new 
ByteArrayOutputStream();

BillPdfer billPdfer = new BillPdfer(selectedBill, 
memoryOutputStream);

billPdfer.writeBillPdf ();

response.setContentLength(memoryOutputStream.size());

ServletOutputStream out = response.getOutputStream();

memoryOutputStream.writeTo(out);

out.flush();
return null;


You could still use Velocity to create your csv, but you'd do it directly 
with Velocity.mergeTemplate rather than via a servlet.

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



Re: vm to return a binary file

2004-11-25 Thread Mike Kienenberger
Ilan Azbel [EMAIL PROTECTED] wrote:
 I am using the Turbine framework. The thing is, I want to leverage off the
 existing database connections that turbine has already made, so I don't 
want
 to create something completely independant. How do I go about doing this?

I don't know enough about turbine to say, but if there's separation between 
the presentation layer and control layer, there must be a way to manually 
construct a response.

In struts, that's done by returning null from an action (indicating that 
you've already built a response object and to not generate a forward).

You might have better chances of getting an answer on the turbine mailing 
list as this is really a turbine question and not a velocity one.

In any case, the code below should be of some help.   It shows what values 
you need to set on a response object and how to write your output into it.  
That should be pretty much the same for any servlet framework.

-Mike



  -Original Message-
  From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
  Sent: 25 November 2004 03:43
  To: [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Subject: Re: vm to return a binary file
 
 
  Ilan Azbel [EMAIL PROTECTED] wrote:
   I would like a vm to return a binary file and thereby instruct
  the browser
   not to display it, but rather to download it. That is, ask the user if
  they
   would like to Open or Save the file.
  
   I would like to do this without any redirecting statements - so
  as soon as
  a
   user requests a certain .vm file, the corresponding java
  creates some type
   of binary data, and the browser immediately asks whether to open or 
save
   this data.
 
  Ilan,
 
  Both your requests to create a csv and a binary file for download are
  generally outside of the scope of velocity servlets.
 
  You'd generally do this using a different servlet.
 
  What servlet framework are you using?
 
  For example, in struts, you'd do something like this in an action
  to create
  a pdf file to download.
  To create another file type (cvs, binary), you'd simply change
  the content
  type and provide a different file generator.
 
  response.setContentType(application/pdf);
  ByteArrayOutputStream memoryOutputStream = new
  ByteArrayOutputStream(); BillPdfer billPdfer = new
  BillPdfer(selectedBill,
  memoryOutputStream); billPdfer.writeBillPdf ();
  response.setContentLength(memoryOutputStream.size());
  ServletOutputStream out = response.getOutputStream();
  memoryOutputStream.writeTo(out); out.flush();
  return null;
  You could still use Velocity to create your csv, but you'd do it 
directly
  with Velocity.mergeTemplate rather than via a servlet.
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
  ---
  Incoming mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.801 / Virus Database: 544 - Release Date: 2004/11/24
 
 
 
 -
 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]



Re: Errors Building Velocity1.4 with J2EE

2004-11-25 Thread Mike Kienenberger
Torsten Schmidt [EMAIL PROTECTED] wrote:
 I want to get my Templates directly from a Database so i must rebuild the 
Velocity Source with the Build Target jar-J2EE. I installed Ant correctly 
and tryed to build the Velocity jar with JDK1.4 and other versions. The 
j2ee.jar is in the correct directory but i became 2 Errors which are like 
this:
 
 ..VelocityServlet.MockServletContext is not abstract and does not override 
abstract mehtod getResourcePaths(java.lang.String) in 
javax.servlet.ServletContext ...
 
 i became a Note: Recompile with -deprecation but this did'nt work. 

I can't help with this error, but I'm surprised that you need to rebuild 
velocity to read templates from a database.

You should be able to do what you need to do either via subclassing or by 
using a custom resource loaders.

-Mike

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



Re: Localized data: best practice - insights appreciated

2004-11-25 Thread Mike Kienenberger
Vincent van Beveren [EMAIL PROTECTED] wrote:
 Ofcourse I could also build a tool, like the 'localeTool' and do the 
 following:
 
 $localeTool.getMessage($product.title)
 
 where $product.title would return some object that contains a string for 
 each locale, and LocaleTool would know how to extract the right string 
 from the bunch. But I find this rather verbose, and it makes the code 
ugly.

$msg.get($product.title) isn't all that verbose, to use the struts version.

Unless you're going to build localization into every single object, you're 
going to need something of that form anyway -- A key that says what you want 
to localize, and a tool to do the localization.


 In my case information is loaded from a database.

That's just a hidden implementation detail, and not really part of the 
problem definition.
I also load my info from a database, but it looks the same in velocity.



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



Re: Referencing arrays

2004-11-15 Thread Mike Kienenberger
Steve O'Hara [EMAIL PROTECTED] wrote:
 I'm trying to reference a 2 dimensional array of strings using the 
following
 td valign=top$Results[0][$velocityCount]/td
 Unfortunately I just get [[Ljava.lang.String;@1684e26[0][x] where x is the
 $velocityCount.

Array notation is not part of the Velocity Template Language.

You can download Shinobu Kawai's ArrayTool to add support for arrays, or you 
can create your own custom tool.

http://wiki.apache.org/jakarta-velocity/ArrayTool

I played around with ArrayTool earlier today, and it seems to work fine.

$array.get($array.get($Results, 0), $velocityCount)

-Mike

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



Re: Velocity DateTool Coding Examples

2004-10-28 Thread Mike Kienenberger
John Reynolds [EMAIL PROTECTED] wrote:
 What I can_t crack is how to use the Date tool IN THE TEMPLATE to format
 the string. Any help is appreciated.

Here's one example in macro format (assumes your DateTool is named date):

#macro (formattedDateTime $dateValue)${date.format(h:mm a M d,  
(zzz), $dateValue)}#end

Or by itself

${date.format(h:mm a M d,  (zzz), $birthday.birthdate)}



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



Re: Velocity DateTool Coding Examples

2004-10-28 Thread Mike Kienenberger
John Reynolds [EMAIL PROTECTED] wrote:
 Hi Mike, thanks for the quick reply!
 
 Here is where i think all those beers from college are taking a toll =)
 
 == assumes your DateTool is named date ==
 
 Can in instantiate the tool from within the template? right now i am not
 putting the tool into the velocity context in my action servlet.

You'll probably be better off keeping the discussion on the list.  I've been 
known to give people mis-advice that has to be corrected by others :)

No, you have to pre-add tools to the context.  You can either do this in 
code (add it just like any other velocity context attribute -- nothing 
special about a tool, it's just a java object assigned to an attribute) or 
you can configure it via web.xml.   You can probably also stick into a 
session/request/application level attribute if you had to, but that's out of 
my experience.

If you're using web.xml, it'd be something like this:

!-- Define Velocity template compiler --

servlet

  servlet-namevelocity/servlet-name

  servlet-class

org.apache.velocity.tools.view.servlet.VelocityLayoutServlet

  /servlet-class



  init-param

param-nameorg.apache.velocity.toolbox/param-name

param-value/WEB-INF/toolbox.xml/param-value

 /init-param



  init-param

param-nameorg.apache.velocity.properties/param-name

param-value/WEB-INF/velocity.properties/param-value

 /init-param



 load-on-startup10/load-on-startup

/servlet





Toolbox.xml looks something like this


?xml version=1.0?



toolbox

  tool

 keydate/key

 scopeapplication/scope

 classorg.apache.velocity.tools.generic.DateTool/class

  /tool

/toolbox


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



Re: #set $var = (boolean exp) == $var = null

2004-10-27 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
 Well, here's what you /can/ do using 1.3:
 
 #set ($listIsEmpty = $list.empty)
 #if ($listIsEmpty)
 no elements!
 #else
 first element : $list.get(0)
 #end
 
 It looks like it's the expression that Velocity doesn't like, and not
 the Boolean.  (It didn't work for ... = !$list.empty)

Thanks for looking into it.

Fortunately, out of my hundreds of templates, I only used that construct 
once, and it was trivial to place it directly in the #if statement.

I never thought to check $list.empty, but that's a variable assignment, not 
a velocity boolean expression.

Probably the best news is that it's fixed in 1.4.

-Mike

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



Re: Formatting price, decimals etc...

2004-10-26 Thread Mike Kienenberger
Manish Hatwalne [EMAIL PROTECTED] wrote:
 How can I format price, decimals etc in VTL?

You'll probably need to use NumberTool.

http://jakarta.apache.org/velocity/tools/generic/
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/NumberTool.html

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



#set $var = (boolean exp) == $var = null

2004-10-26 Thread Mike Kienenberger
I suppose in retrospect since Velocity is String-oriented, this behavior is 
to be expected, but it sure seems counter-intuitive that

#set ($listHasElements = ($list.size()  0))

#if ($listHasElements)


for lists containing elements does not work, but 

#if ($list.size()  0)


does.

Maybe my pointing this out will save someone else some pain.

-Mike

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



Re: #set $var = (boolean exp) == $var = null

2004-10-26 Thread Mike Kienenberger
Shinobu Kawai [EMAIL PROTECTED] wrote:
 Hi Mike,
 
  I suppose in retrospect since Velocity is String-oriented, this behavior 
is
  to be expected, but it sure seems counter-intuitive that
  
 #set ($listHasElements = ($list.size()  0))
  
 #if ($listHasElements)
  
  for lists containing elements does not work, but
  
 #if ($list.size()  0)
  
  does.
 I wonder why it works in my environment?
 
 #set ($listHasElements = ($list.size()  0))
 $listHasElements
 
 should show $listHasElements, right?  But it was true.  It worked
 for both 1.4 and CVS HEAD.
 
 Maybe there's something wrong with your $list.

Nope, but maybe the behavior changed in 1.4.  I'm using 1.3.1.

The list definitely exists and has elements.

-Mike

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



Re: Conditional display - Approach question

2004-10-20 Thread Mike Kienenberger
Manish [EMAIL PROTECTED] wrote:
 (1) Put a conditional check in velocity template while iterating though a
 list to decide if the book should be displayed. It would be sth like this 
-
 
 #foreach($book in booklist)
 #if($StockManager.isAvailable($book.number))
  ## do whatever here...
 #end
 ## don't display anything if book is not available
 #end
 
 (2) Another approach is to check this in VARIOUS actions while creating 
the
 list itself if the book should be added to the list at all.
 
 First approach sounds easier to implement, but it means that the view part
 is taking decision about business logic, which sounds not so nice
 Second approach is difficult because there are many actions that will have
 to be changed, besides there are many programmers working on various
 actions, so they all need to take care of that. So I am trying to avoid
 this However, there's one more advantage here, if I do it this way I 
can
 add a unit test to check that only available books are getting added.

If you want to be a purist, you probably need to decide if it's business 
logic or display logic.  Is there any chance you'll eventually want to 
display non-available books?

If you decide it's business logic, another option would be to forward 
everything to a filtering action which then forwards to your display action. 
 The logic would still be separate from the view logic, but you'd have 
chained them together in your config file.  This is probably how I'd do it.


 p.s. BTW, is there anything similar to Java continue in VTL?

If you're talking about #foreach loops, in standard velocity there's 
nothing.   There may-or-may-not be a #stop directive you can install as a 
patch in the bugzilla database, but I use an #if statement.

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



Re: Velocity

2004-10-15 Thread Mike Kienenberger
Wong, RYM (Richard)  [EMAIL PROTECTED] wrote:
 Hi,
 
 I cannot find out whether VTL is case sensitive or not in the on-line
 reference manual.
 
 e.g. Are the reference variables $var  and $VaR regarded as the same
 variable?

I'm fairly certain they are case sensitive.

The easiest and most authoratative way to find out is to just try it, of 
course :)

-Mike

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



Re: Avoiding Line Breaks in macros

2004-10-14 Thread Mike Kienenberger
Alexandre Torres [EMAIL PROTECTED] wrote:
 Hi.
 It is possible to avoid line break generation when calling a macro?
 for example:
 #macro (duh)
 John
 #end
 ...
 after the joke #daa() said duh.
 ...
 This will generate:
 
 after the joke John ---line break
 said duh.
 
 I'm trying to generate no HTML content, so, it will be important to
 control line break and space generation. I took a look in the docs,
 but can't find much about this.
 Should I use classes instead of macros (well, macros are much better in my 
case)
 
 I 'm a little bit lost in this line break generation with #comands
 too, I did search in the past messages but it's hard to find
 information (or I'm too newbie in velocity).
 
 Thanks for any tip.

I find whitespace in velocity confusing and somewhat inconsistent.

Two general rules are:

Whatever line breaks you put in are left in.
If a line ends with a #command, the line break is not displayed.

So,

#macro(duh)John#end

is what you want.


Your best bet is to play around with stuff until it does what you want it to 
do.
Another useful thing you might need is #**# which is an empty inline 
comment that you can use to separate other commands and variables.

One thing to watch out for is that ending the final line with ## will cause 
a fatal error.

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



Re: Can we access velocity contexts from inside javascript

2004-10-13 Thread Mike Kienenberger
Barbara Baughman [EMAIL PROTECTED] wrote:
 Velocity is rendered on the server side, replacing Velocity code with
 strings, not any Java or Javascript object.  The rendered template is
 sent to the browser client.  When javascript attempts to work on the
 client side there is no VelocityContext to work with any more.  So be
 sure your rendered code already has the information javascript needs
 from the Velocity context before sending it to the client.

And if you need velocity context data made available to your javascript, 
then, in your velocity template, you need to generate the javascript code to 
create that data so the data is available once the web browser receives and 
interprets the javascript.

-Mike

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



Re: restricting access to velocity templates

2004-04-16 Thread Mike Kienenberger
Michael Kucera [EMAIL PROTECTED] wrote:
 Right now if you type something like
 www.myapp.ca/templates/welcome.vm into the browser the template is
 rendered for the user but the required data is missing and it looks like
 a mess. How do I selectively restrict access just to the templates
 without interfering with the way struts works? Am I missing something
 simple? Am I totally way off? Any help would be appreciated. Thanks.

Move your templates (and anything else you don't want visible via direct 
access) inside WEB-INF.

-Mike

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



Re: double parsing

2004-03-18 Thread Mike Kienenberger
Demetz Markus [EMAIL PROTECTED] wrote:
 hello,
 
 i'm very new to velocity
 i want to do a think like following:
 
 my context looks like this:
 
 context.put(name1, something),
 context.put(name2, somethingelse), ...
 
 my temlate has a loop:
 #foreach($record in $list)
   $name$velocityCount
 #end
 
 the result only is $name1 $name2 but I would like to have the context of
 $name1 $name2 - something and something else...
 is this possible?

You can do this with the eval method of the RenderTool.

http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/RenderTool.html

However, you might be better off changing the data struture(s) that you're 
putting into your context rather than building variables in the template.

For example, put the names in a map with the $record as a key, or create a 
new data struture that contains both record and names and put them in a 
list, or just put the names in a list.

-Mike

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



Re: Change to allow newlines in directives and + as a string concatenator

2003-12-23 Thread Mike Kienenberger
Geir Magnusson Jr [EMAIL PROTECTED] wrote:
 I committed two changes that I think need community review. (Well, the 
 second does).
 
 The first is that you can use newlines in directives
 
 #foreach($foo
 in
 $bar)
 
 or
 
 #macro(
   foo
   $a
   $b
   )
 
 etc.
 
 The second, which I think we should agree on, is to use '+' as the 
 string concatenation operator, so you can :
 
 #set($longstring = this is a long 
 + string that you can do over 
 + multiple lines)

Anything that makes Velocity less fragile and more intuitive is a Good Thing 
in my opinion.
Both of these do that.

(I had a 20-argument macro all crammed on one line just earlier this week 
that really could have benefitted from newlines.)

-Mike

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