Markus,

The problem I see with the template approach is that what happens when you
do error handling? For instance, what if the guestbook.newEntry call is a
duplicate? You can't throw an exception. You'd have to return an error code
or error container object- which is getting kludgy also. 

If I did go with a form destination template, I think an alternative to your
approach would be to use a $response.sendRedirect back to the index.vm page
as opposed to #parse-ing it into your template file. That way you could have
some error related branching in the template without big if blocks. The
sendRedirect acts like an immediate escape. You could also pass parameters
to the destination page via the URL which you can't do with the #parse. Of
course, you end up with a template with no html in it and that is never
viewed - which is weird.

Maybe Nathan has an opinion of which approach is best.

Regards,

Matt


Markus Auchmann wrote:
> 
> Hi Matt,
> 
> I had the same issue a few days ago, and i have chosen the 2nd way you
> described:
> 
> I created a index.vm with the form and the main template. In the form I
> pointed to another .vm let's call it newEntry.vm. There I used the
> Paramter
> Parser tool to get the post data and then I called a java function to
> update
> the database (which you have to write yourself):
> 
> newEntry.vm
> --------------------------
> $guestbook.newEntry($!params.getString('name'),
> $!params.getString('mail'),
> $!params.getString('homepage'), $!params.getString('text'))
> 
> #parse("index.vm")
> --------------------------
> 
> Next I just included the index.vm to once again show the user the main
> template (as you can guess, it's a guestbook).
> 
> Greets,
> Markus
> 
>> -----Original Message-----
>> From: Matt L. [mailto:[EMAIL PROTECTED]
>> Sent: Wednesday, December 27, 2006 11:59 PM
>> To: [email protected]
>> Subject: VVS Form Submission - Best Practices
>> 
>> 
>> I am using the VelocityViewServlet (VVS) and I would like to handle html
>> form
>> submission that will be writing to a database. What is the best
>> practice/industry standard way of doing this?
>> 
>> Just off the top of my head I can think of two ways. One would be to use
>> an
>> entirely different servlet to handle the form submissions. It's certainly
>> more appealing to have everything going through the VVS - two servlets
>> seems
>> pretty kludgy to me..
>> 
>> I could also have a destination template read the parameters and, via a
>> tool, write to the database. My concern there is that the Velocity
>> template
>> language may not be rich enough to pull off that level of functionality.
>> I
>> also wonder about performance.
>> 
>> I'm sure there is something obvious that hasn't occurred to me. I looked
>> in
>> the documentation and searched online, but I didn't find anything to
>> address
>> this. Regardless, I apologize for asking such a basic question.
>> 
>> Thanks,
>> 
>> Matt
>> --
>> View this message in context:
>> http://www.nabble.com/VVS-Form-Submission---
>> Best-Practices-tf2888050.html#a8068626
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> 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]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/VVS-Form-Submission---Best-Practices-tf2888050.html#a8080294
Sent from the Velocity - User mailing list archive at Nabble.com.


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

Reply via email to