Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Velocity template - populating with form values

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'd really appreciate some help on this one.
I'm using a *.vm file to generate an xml request. The elements in the request are populated from parameters passed from a html form. I have a series of checkboxes whose values I want to pass to the velocity/xml template. Here's a snippet of the template which I want to populate:


So say I have a 5 checkboxes on my form and the user checks 3 of them, how to I pass the values to this template so that the vas:RespondWith> tag is only generated 3 times?

Thanks in advance,

Ruth
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you know how velocity works. It has something called the velocity context and whatever objects you put in there , are available to the vm files during its processing.

So make an arraylist with the values that you have collected from your HTML and put that in velocity context and use for loop of VTL (Velocity Template Language) for populating in the final output(XML in your case).
 
Ruth Marx
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so does the for loop go in the actual template in the <vas:RespondWith></vas:RespondWith> tag?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ruth Marx:
Ok so does the for loop go in the actual template in the <vas:RespondWith></vas:RespondWith> tag?



Yes, the #foreach loop goes into the actual VM file.

Reference : http://velocity.apache.org/engine/devel/vtl-reference-guide.html

Hope this helps,
[ July 25, 2007: Message edited by: Rahul Bhattacharjee ]
 
Ruth Marx
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for taking the time to reply.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!