You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Sam Baker <sa...@sc.edu> on 2002/01/21 15:42:53 UTC

Template for creating validating survey forms?

Dear Folks:

I've been writing some on-line survey forms with validation, using
servlets and
JavaServer Pages (JSPs).  My question is:  Are there templates available
for automatically generating the Java code and files needed to take an
HTML form and create a JSP form with validation?  For an explanation of
what I'm asking, please read on ...

Survey forms ask questions using HTML input tags.  Often, you want to
validate the answers, meaning checking to see that required questions
were answered and that the answers are reasonable.

My first attempt at a survey form with validation had a lot of Java code
in the JSP files.  It works, but it's hard to make changes.

For my second attempt, I followed the model in David M. Geary's Advanced
JavaServer Pages, Chapter 3, Section 8. A heirarchy of classes is
created, working up to generic form input elements.  For example, Geary
has a generic radio button element that extends a string-response
element.  To create an on-line form with validation using this method,
each input element in the form has its own Java bean.  There is also a
bean for the whole form.  And there is the JSP file for the form itself.

Creating all this by hand involves a lot of repetitive typing, with many

possibilities for error.  The Java bean capitalization conventions must
be followed
perfectly.

To make this process less error-prone, I wrote an applet.  The interface

is crude, I admit, but it does what I need.  You can find the applet at:

http://hadm.sph.sc.edu:8080/show/RadioFormGenerator.html

The applet generates Java code for radio buttons.  You fill in the
second and third boxes with the radio button name and value.  Press
Enter, and you get an HTML input tag in the top box for copying into the

form's main JSP file. In the 4th box, you get code for pasting into the
form bean source code.  In the bottom box, you get code for creating the

bean for this radio button element.

This applet eliminates my capitalization errors (unless it has mistakes
I haven't fixed yet), but using it requires a lot of copying and
pasting.

After reading some not-so-recent JavaWorld articles (including
Messerschmidt's article on Velocity in the July 2001 issue) it occurs
to me that it ought to be possible to write a system of templates and
java classes that could read a plain HTML form, parse the text to pick
out the input tags, and then generate all the needed files.  The form
designer would then only have to customize the validation code,
compile all the java files, and set up the webapp on Tomcat.  .

My question is:  Has this been done already? Is such a template
system available through some open source project?
If not, I might write one myself and come back here to ask how to make
it available.

-- Sam





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


Re: Template for creating validating survey forms?

Posted by Gabriel Sidler <si...@teamup.ch>.
Sam,
check out the form validation frameworks that have been contributed to 
Jakarta Struts:

http://husted.com/struts/resources.htm (search for Validator)

Specifically I recommend looking at Dave Winterfeldt's form validation
framework at: http://home.earthlink.net/~dwinterfeldt/ I havn't used it
myself but many people recommend it highly.

HTH
Gabe

PS: We are working on a Struts/Velocity integration. See announcement
on the Velocity home page.



Sam Baker wrote:
> 
> Dear Folks:
> 
> I've been writing some on-line survey forms with validation, using
> servlets and
> JavaServer Pages (JSPs).  My question is:  Are there templates available
> for automatically generating the Java code and files needed to take an
> HTML form and create a JSP form with validation?  For an explanation of
> what I'm asking, please read on ...
> 
> Survey forms ask questions using HTML input tags.  Often, you want to
> validate the answers, meaning checking to see that required questions
> were answered and that the answers are reasonable.
> 
> My first attempt at a survey form with validation had a lot of Java code
> in the JSP files.  It works, but it's hard to make changes.
> 
> For my second attempt, I followed the model in David M. Geary's Advanced
> JavaServer Pages, Chapter 3, Section 8. A heirarchy of classes is
> created, working up to generic form input elements.  For example, Geary
> has a generic radio button element that extends a string-response
> element.  To create an on-line form with validation using this method,
> each input element in the form has its own Java bean.  There is also a
> bean for the whole form.  And there is the JSP file for the form itself.
> 
> Creating all this by hand involves a lot of repetitive typing, with many
> 
> possibilities for error.  The Java bean capitalization conventions must
> be followed
> perfectly.
> 
> To make this process less error-prone, I wrote an applet.  The interface
> 
> is crude, I admit, but it does what I need.  You can find the applet at:
> 
> http://hadm.sph.sc.edu:8080/show/RadioFormGenerator.html
> 
> The applet generates Java code for radio buttons.  You fill in the
> second and third boxes with the radio button name and value.  Press
> Enter, and you get an HTML input tag in the top box for copying into the
> 
> form's main JSP file. In the 4th box, you get code for pasting into the
> form bean source code.  In the bottom box, you get code for creating the
> 
> bean for this radio button element.
> 
> This applet eliminates my capitalization errors (unless it has mistakes
> I haven't fixed yet), but using it requires a lot of copying and
> pasting.
> 
> After reading some not-so-recent JavaWorld articles (including
> Messerschmidt's article on Velocity in the July 2001 issue) it occurs
> to me that it ought to be possible to write a system of templates and
> java classes that could read a plain HTML form, parse the text to pick
> out the input tags, and then generate all the needed files.  The form
> designer would then only have to customize the validation code,
> compile all the java files, and set up the webapp on Tomcat.  .
> 
> My question is:  Has this been done already? Is such a template
> system available through some open source project?
> If not, I might write one myself and come back here to ask how to make
> it available.
> 
> -- Sam
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland

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