How to Create Web Pages With Forms (Web Developer)

Draft 0.5
July 19, 2000
Ted Lee (tlee@startups.com)

1. Applicability

This is a cookbook on how to create web pages with forms from the perspective of the web developer.

Read this document when all of the following are true:

If this document doesn't meet your needs, you may want to look at:

2. Steps for Creating Web Pages With Forms

Typically there will be at least three people involved in building a form--a web developer, a Java programmer, and a site producer.  Briefly, the responsibilities of each are: The specific responsibilities of each for producing web forms are shown in the high level picture below:

The following is a detailed description of the three balloons that involve you, the web developer.  The steps you need to take to build a form, along with an example set of pages.  The summary is:
  1. Agree on a state model of the web site
  2. Design preliminary static web pages for each state
  3. Test the static web pages for layout accuracy
  4. Make the pages available to the Java developer
  5. If needed, make appearance changes to the pages

2.1  Agree On a State Model Of the Web Site

Before you start creating a page, you will ideally have a spec of what the pages are supposed to do.  This might be a verbal description or a more formal set of documents.  The first thing you should do is to find, discover, or create a state model of the set of web pages you intend to build.  The state model does the following: If you're lucky, your site producer will have already produced the state model for you.  However, it doesn't matter who creates the state model--it could be you, it could be the information architect who designed the spec, it could be the Java developer.  The important thing is that everybody agrees on the same state model, since all the coding that everybody does will be affected by it.  The following supersimplified example shows how you might create a state model.  Imagine that the following images are a spec for a series of web pages to be built:

"We want a page with a form where we can enter the name of an existing user in a textfield and a legal structure from a pulldown.  We will retrieve the legal structure pulldown entries from the database (we can't just put them into html).  It should look something like this."

"Also, if the username is invalid and the user submits, it should come back to this page and highlight Username in red, along with a message that says what the problem was."
"When the username is really valid, hitting submit should take them to a success page which shows the userID and the email address of that user."


The first thing to do is to name all the pages.  Try to pick something which is descriptive of the user task, or the state that the user is in when they are looking at the page.  For example, you might pick:

Then draw a state diagram showing the possible transitions between the pages:
The balloons indicate states, and the arrows indicate transitions between states.  Note that the EnteringUserName state has a state transition that leads back to the same state--if the username isn't valid, it sends you back into the same state (with appropriate error messages).  Please make sure that everyone (you, the Java developer, the spec writer) agree on the state model!

2.2 Design Preliminary Static Web Pages For Each State

Each state will be represented by a jsp file.  Name your jsp file <stateName>.jsp.  For example, for the state EnteringUserName shown above, you would create jsp file called EnteringUserName.jsp.  In the jsp file, enter the HTML for the elements in the page.  For now, don't worry about what happens when someone submits the form.  For example, your initial cut at EnteringUserName.jsp might look like:
<HTML>
<HEAD>
<TITLE> Test MVC Page </TITLE>
</HEAD>
<BODY>

<H1> Test MVC Model </H1>
<FORM ACTION="#" METHOD="POST">
 

<B>Username:</B>
<INPUT TYPE="TEXT"
       NAME="#"
       VALUE="#"
       SIZE="20"
       MAXLENGTH="40">

<P>

<B>Legal Structure</B>
<SELECT NAME="#">
<OPTION VALUE="#">#
</SELECT>

<INPUT TYPE="SUBMIT">
</FORM>
</BODY>
</HTML>

And Success.jsp might look like:
<HTML>
<HEAD>
<TITLE> Test MVC Page Success</TITLE>
</HEAD>
<BODY>

<H1> Success! </H1>

<B>UserID:</B> # <BR>
<B>Email Address:</B> # <BR>

</BODY>
</HTML>


Notice the hash marks.  These are placeholders for variables that the Java developer will have to fill in later.

Note that there is no EnteringUserNameError.jsp page.  You don't have to create it!  In general, you don't have to worry about error pages that are very similar to existing pages like EnteringUserName.jsp.  The reason is that the only difference between the error page and the non-error page is dynamically generated content, so you're off the hook.

Also, for text fields be aware that you may not have control over the maximum length of the text fields due to database concerns.  Don't worry to much about getting the field max lengths exactly right--the Java developer will have the opportunity to change them later.

2.3 Test The Static Pages For Layout Accuracy

You should be able to open your newly created pages with a web browser (you may need to rename the file to end in .html for your browser to recognize them).  Show them to the person who is responsible for the spec and get feedback.  The reason you're doing this now is because changes are relatively cheap now, while there is just HTML.  Changes get more expensive when Java coding has started.  Continuing with our little example, let's say you've gotten feedback and the following pages have been more or less agreed on:

EnteringUserName.jsp:

Success.jsp:
Editor's note:  please ignore the absurdity of any site producer ok-ing the pathetic screens shown above.  This is just a toy example!

You are now ready to begin the process of collaborating with a Java developer to put some logic behind the forms.

2.4 Make the Pages Available to the Java Developer

Once you've finished the HTML markup of the jsp files, it's time to make them available to the Java developer.  Do this as follows:

Put the jsp files in the appropriate directory in your own staging development environment.

Most likely it will be someplace under startups/su_htdocs/staging/ under your home directory.  You may need to create one or more subdirectories to place the files in, depending on your site file organization plan.  Continuing with the example, let's say the files are supposed to live under a directory called "testmvc" so that they appear under http://ted.startups.com/testmvc:
rabbit:/export/home/ted% cd startups/su_htdocs/staging
rabbit:/export/home/ted/startups/su_htdocs/staging% mkdir testmvc


[use absoluteftp or some other application to get the files from your desktop to the newly created directory "testmvc"]

Add the files to CVS using "cvs add <filename>".

rabbit:/export/home/ted/startups/su_htdocs/staging/testmvc% ls
total 11
   2 EnteringUserName.jsp          
   3 EnteringUserNameError.jsp    
   1 Success.jsp                  
rabbit:/export/home/ted/startups/su_htdocs/staging/testmvc% cvs add EnteringUserName.jsp
(etc.)

Commit the the add using "cvs commit <filename>".

rabbit:/export/home/ted/startups/su_htdocs/staging/testmvc% cvs commit EnteringUserName.jsp
(etc.)

Tell the Java developer that the files are ready and in CVS.

The Java developer will replace your # characters with meaningful names and make the changes available to you through CVS (you will have to do a cvs update in order to get the changes to your local directory).  Be aware that it might take some time for the Java developer to add the necessary jsp code.  Continuing with our example, the Java developer might make the following changes and commit them to CVS (red items are values that the Java developer has substituted for your # marks, while the blue text is additional jsp scripting code that has been added)

EnteringUserName.jsp:

<%--
 * Copyright 2000 Startups.com. All Rights Reserved.
 *
 * This software is the proprietary information of Startups.com.
 * Use is subject to license terms.
 *
--%>
<%@ page import="com.startups.testmvc.EnteringUserNameModel" %>

<jsp:useBean id="enteringUserNameModel" class="com.startups.testmvc.EnteringUserNameModel" scope=
"session" create="yes"/>

<HTML>
<HEAD>
<TITLE> Test MVC Page </TITLE>
</HEAD>
<BODY>

<H1> Test MVC Model </H1>
<%= enteringUserNameModel.displayFailedValidations() %>

<FORM ACTION="/servlet/com.startups.testmvc.EnteringUserNameServlet" METHOD="POST">
 

<%= enteringUserNameModel.fontColorTagFor("UserID") %>
<B>Username:</B>
</FONT>
<INPUT TYPE="TEXT"
       NAME="UserID"
       VALUE="<%= enteringUserNameModel.getUserID() %>"
       SIZE="20"
       MAXLENGTH="40">

<P>

<B>Legal Structure</B>
<SELECT NAME="LegalTypes">
<%
    String[] theLegalTypes = enteringUserNameModel.getLegalStructures();
    for (int i = 0; i < theLegalTypes.length; i++) {
        %>
        <OPTION VALUE="<%= theLegalTypes[i] %>"><%= theLegalTypes[i] %>
        <%
    }
%>
</SELECT>

<INPUT TYPE="SUBMIT">
</FORM>
</BODY>
</HTML>

Success.jsp:
<%--
 * Copyright 2000 Startups.com. All Rights Reserved.
 *
 * This software is the proprietary information of Startups.com.
 * Use is subject to license terms.
 *
--%>
<jsp:useBean id="successModel" class="com.startups.testmvc.SuccessModel" scope="session" />

<HTML>
<HEAD>
<TITLE> Test MVC Page Success</TITLE>
</HEAD>
<BODY>

<H1> Success! </H1>

<B>UserID:</B> <%= successModel.getUserID() %> <BR>
<B>Email Address:</B> <%= successModel.getEmailAddress() %> <BR>

</BODY>
</HTML>

At some point, the Java developer will have enough back-end Java code available so that the form will actually do something when you point your web browser at your development web server (e.g. http://ted.startups.com/testmvc/EnteringUserName.jsp).  In order for this to work, you will have to perform a cvs update and recompile the Java code for your development environment.

2.5  If Needed, Make Appearance Changes To The Pages

You should be able to change the appearance of the pages without requiring any help from the Java developer.  For example, let's say you wanted to put the fields in the Success page into a table.  You could change the page by adding html tags:
<%--
 * Copyright 2000 Startups.com. All Rights Reserved.
 *
 * This software is the proprietary information of Startups.com.
 * Use is subject to license terms.
 *
--%>
<jsp:useBean id="successModel" class="com.startups.testmvc.SuccessModel" scope="session" />

<HTML>
<HEAD>
<TITLE> Test MVC Page Success</TITLE>
</HEAD>
<BODY>

<H1> Success! </H1>

<TABLE>
<TR>
<TD><B>UserID:</B> <%= successModel.getUserID() %> </TD>
<TD><B>Email Address:</B> <%= successModel.getEmailAddress() %> </TD>
</TR>
</TABLE>

</BODY>
</HTML>

Continue to make whatever changes are necessary.  There is no need to tell the Java developer what you are doing, as long as you are not adding new fields.  When you commit the changes to CVS the Java developer will get them the next time he or she does a cvs update.  Likewise, when the Java developer makes changes to the scripts in the jsp files, you'll get these changes when you do cvs updates.

Finally, when the whole thing does what it's supposed to do, you should get a signoff from your site producer.  Congratulations, you're done!  Hopefully these steps have allowed you to concentrate on and own the part that you do best--the appearance of the page--while allowing the Java developer to do what he or she does best without a lot of back and forth.

3 Design Discussion

If you want to know more about why these steps are the way they are, see this document.

4 Version History

0.5, July 19, 2000.  Changed EnteringUserName.jsp listing and state diagram to reflect error-handling portions.
0.4, June 30, 2000.  Added discussion about roles, added site producer.
0.3, June 29, 2000.  First version of document split into Web developer and Java developer documents.